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());
精彩评论