开发者

Error instantiating an interface

The following code fails to compile with message: cannot instantiate type SymmetricKey SymmetricKey is an interface. How do I fix this?

 ByteArrayOutputStream bao开发者_JAVA百科s = new ByteArrayOutputStream(); 
 InitializationVector iv = new InitializationVector("helo".getBytes());
 SymmetricKey key = new SymmetricKey("AES_256","key", 0, "key".length());
 OutputStream os = EncryptorFactory.getEncryptorOutputStream(key, baos, "AES/CBC/PKCS5",);
 os.write("somedata".getBytes());
 byte[] encryptedData = baos.toByteArray();
 ByteArrayInputStream bais = new ByteArrayInputStream(encryptedData);
 InputStream is = DecryptorFactory.getDecryptorInputStream(key, bais, "AES/CBC/PKCS5", iv); 


I solved my problem by using SymmetricKeyFactory

SymmetricKey key=
    SymmetricKeyFactory.getInstance("AES_256","key".getBytes(), 0, "abc123".length());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜