有沒有辦法生成適合使用Sun的keytool程序進行加密的128位密鑰對?似乎http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator中的算法不支持或不允許短於512位的密鑰。使用keytool生成128位密鑰
密鑰對將與ff一起使用。代碼段:
Security.addProvider(new BouncyCastleProvider());
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream keyStoreSource = new FileInputStream("keystore");
try {
keyStore.load(keyStoreSource, "password".toCharArray());
} finally {
keyStoreSource.close();
}
String alias = (String) keyStore.aliases().nextElement();
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, "password".toCharArray());
X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias);
CMSEnvelopedDataStreamGenerator generator = new CMSEnvelopedDataStreamGenerator();
generator.addKeyTransRecipient(certificate);
OutputStream output2 = generator.open(output, CMSEnvelopedDataGenerator.AES128_CBC, BouncyCastleProvider.PROVIDER_NAME);
try {
IOUtils.copy(input, output2);
} finally {
output2.close();
output.close();
}
其中輸出是一些爲OutputStream其中的加密數據將被保存,輸入是一些的InputStream其中明文數據將被讀取。
我一直在尋找生成測試證書的AES-128使用。那麼我錯了嗎? – 2009-05-19 10:10:10
你能否詳細解釋一下你想完成的事情? – 2009-05-19 11:39:26