Java 第三方公钥 RSA加密求助
--------------------编程问答-------------------- 已找到解决方法,可以采用如下方法,就可以避免了:private byte[] getEncSymmKey(byte[] pubkeyBuf, byte[] randomKey) throws Exception {
byte[] bX509PubKeyHeader = { 48, -127, -97, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -127,
-115, 0 };
byte[] bPubKey = new byte[pubkeyBuf.length + bX509PubKeyHeader.length];
System.arraycopy(bX509PubKeyHeader, 0, bPubKey, 0, bX509PubKeyHeader.length);
System.arraycopy(pubkeyBuf, 0, bPubKey, bX509PubKeyHeader.length, pubkeyBuf.length);
X509EncodedKeySpec rsaKeySpec = new X509EncodedKeySpec(bPubKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey rsaPubKey = keyFactory.generatePublic(rsaKeySpec);
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
cipher.init(Cipher.ENCRYPT_MODE, rsaPubKey);
return cipher.doFinal(randomKey);
}
补充:Java , Java相关