bouncycastle

How to encrypt and decrypt files with bouncy castle (DES) in netbeans java?

﹥>﹥吖頭↗ 提交于 2019-12-08 13:02:16
问题 How can I encrypt and decrypt files (not strings) with bouncy castle (DESEngine)? I have searched before but could not find help. 回答1: Sorry, I have solved this by myself. Here is my code: Tesbouncy.java package tesbouncy; import org.bouncycastle.crypto.*; import org.bouncycastle.crypto.engines.*; import org.bouncycastle.crypto.modes.*; import org.bouncycastle.crypto.paddings.*; import org.bouncycastle.crypto.params.*; public class Tesbouncy { BlockCipher engine = new DESEngine(); public byte

Why are these square symbols appended after decrypting with bouncy castle?

旧巷老猫 提交于 2019-12-08 12:20:27
问题 I have created a simple java method that encrypts and decrypts text using the bouncy castle library. Encryption works as expected but when I decrypt something I get these extra square symbols at the end: I think this might be something to do with padding but I've followed the example featured on bouncy castle's website, so I really can't understand why I would be getting this sort of output. Here is the code I am using: [Main] public static void main(String[] argv) { String ciphertext =

Should I validate an embedded timestamp in a PAdES signature when doing signature verification?

五迷三道 提交于 2019-12-08 12:20:26
问题 I'm trying to understand if and how I should validate a PAdES signature with an embedded timestamp. This embedded timestamp is obtained from a timestamp authority (TSA). If the signature includes crl file or ocsp response, we should generally first validate the chain of certificates from the signature is not expired nor revoked at the date corresponding to this timestamp. As the timestamp from a TSA is also signed, I'm trying to figure out if I should also validate the chain of certificates

Cannot verify signature (cmssigneddata) bouncycastle

流过昼夜 提交于 2019-12-08 11:39:38
问题 When I want to verify my signature made with BouncyCastle I don't get into the second while loop of the verifySignature method. The store.getMatches() gives back an empty array. public static CMSSignedData sign() throws Exception { byte[] file = fileChooser(); store = KeyStore.getInstance(storeType); FileInputStream in = new FileInputStream(new File(storePathKey)); store.load(in, storePassword); in.close(); Key priv = store.getKey("Subject", storePassword); System.out.println(priv.toString()

Java signing files with BouncyCastle - Create signature of a file using secret keyring

坚强是说给别人听的谎言 提交于 2019-12-08 09:29:17
问题 I'm trying to write a Java program that signs a file with a private key. The program takes 3 arguments - file, secret keyring and a password. The output should be in a detached file *.bpg. The problem is that I get the following errors when I try to compile my code: C:\CNS3\BCastle>javac Sign.java Note: Sign.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. My code is as follows: import java.io.*; import java.security.*; import java.util.Iterator;

Decrypting aes-256-cbc using bouncycastle

二次信任 提交于 2019-12-08 04:09:37
问题 New to bouncyCastle, any help appreciated. I am trying to decrypt a file encrypted by third party on my system using bounncycastle java API. It seems to decrypt file fine except for the blob of junk data at the beginning on the decrypted file.Code below PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher( new AESEngine())); CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(DatatypeConverter.parseHexBinary(keyInfo.getKey())), DatatypeConverter

Creating keystore BKS for https android connection

元气小坏坏 提交于 2019-12-08 03:15:17
问题 I found tutorial which describes how create and use keystore for https connection. But I have very noob question: where should i put this code to create keystore? at the openssl command promt or in keytool key prompt. export CLASSPATH=bcprov-jdk16-145.jar CERTSTORE=res/raw/mystore.bks if [ -a $CERTSTORE ]; then rm $CERTSTORE || exit 1 fi keytool \ -import \ -v \ -trustcacerts \ -alias 0 \ -file <(openssl x509 -in mycert.pem) \ -keystore $CERTSTORE \ -storetype BKS \ -provider org.bouncycastle

BouncyCastle, how long should it take to generate a RSA keypair?

旧城冷巷雨未停 提交于 2019-12-08 02:43:26
问题 I'm using Bouncy Castle (c#/vb.net version) and generating a 4096-byte RSA Keypair to use in my certificate with this routine: Public Shared Function GenerateRSAKeypair(keylength As Integer) As AsymmetricCipherKeyPair Dim r As New RsaKeyPairGenerator() r.Init(New KeyGenerationParameters(New SecureRandom(), keylength)) Dim keys As AsymmetricCipherKeyPair = r.GenerateKeyPair() Return keys End Function The procedure works ok, however it takes a very long time, up to one minute (I'm on a 2.4ghz

how to load the private key from a .der file into java private key object

不想你离开。 提交于 2019-12-08 02:20:35
问题 I'm writing a java program to import private keys from files within the file system and make a private key object, using java... I could do it for files in .pem format but, with .der format, I had no idea what to do, since I couldnt firstly detect the algorithm used to generate the keys. within .pem files I could determine the algorithm from the header for PKCS#1 which have a header like -----BEGIN RSA PRIVATE KEY---- formats and used the bouncycastle pem reader for those in PKCS#8 which have

Java byte array to ECCPrivateKey - InvalidKeySpecException: encoded key spec not recognised

非 Y 不嫁゛ 提交于 2019-12-08 02:14:54
问题 When I try to make ECC private key from byte array, I get exception mentioned below. I have public/private keys and out signed output from C library micro-ecc/uECC.h. C used secp192r1 curve. I am trying to verify data with C generated keys in Java. How to convert byte array to private/public key? Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); byte[] kb = new byte[]{(byte)0x24, (byte)0xF4, (byte)0x36, (byte)0x16, (byte)0xD0, (byte)0x96, (byte)0x12, (byte)0x63,