2010-11-30 13 views
2

Le code suivant ne peut pas être compilé avec le message: cannot instantiate type SymmetricKey SymmetricKey est une interface. Comment puis-je réparer ça?Erreur lors de l'instanciation d'une interface

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); 

Répondre

2

Je résolu mon problème en utilisant SymmetricKeyFactory

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