2010-11-30 102 views
2

以下代碼無法編譯消息:cannot instantiate type SymmetricKey SymmetricKey爲 接口。我該如何解決?實例化接口時出錯

ByteArrayOutputStream baos = 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); 

回答

2

我用SymmetricKeyFactory

SymmetricKey key= 
    SymmetricKeyFactory.getInstance("AES_256","key".getBytes(), 0, "abc123".length()); 
解決我的問題