我用对称密钥加密我的消息,对称密钥本身必须用不同的 RSA 公钥进一步加密。当我尝试实现上述内容时,出现以下错误:
javax.crypto.IllegalBlockSizeException: The input was invalid: Invalid input length.
at com.rsa.shareCrypto.j.hD.engineDoFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at wrap1.main(wrap1.java:69)
有没有办法解决这个问题?
我需要做这样的事情[[[[key]PK-A]PK-B]PK-C],其中PK-A = A的公钥,类似PK-B和PK-C。
以下是我在这里尝试的代码是代码
String InitialKey = "2011BCSChampionA";
byte[] initkey = InitialKey.getBytes();
// First level encryption of the key
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] cipherData = cipher.doFinal(initkey);
// Second level of encryption
KeyPairGenerator keyGen1 = KeyPairGenerator.getInstance("RSA");
keyGen1.initialize(1024);
KeyPair keypair1 = keyGen1.genKeyPair();
PrivateKey prvKey = keypair1.getPrivate();
PublicKey pubKey = keypair1.getPublic();
Cipher cipher1 = Cipher.getInstance("RSA");
cipher1.init(Cipher.ENCRYPT_MODE, pubKey);
byte[] cipherData_new = cipher1.doFinal(cipherData);