Twofish encryption: "java.security.NosuchAlgorithnException:Twofish KeyGenerator not available" error

431 views Asked by At

This is the code to generate key for twofish algo and to encrypt using it.

SecureRandom sr = new SecureRandom(key.getBytes());
KeyGenerator kg = KeyGenerator.getInstance("twofish");
kg.init(sr);
SecretKey sk = kg.generateKey();

// create an instance of cipher
Cipher cipher = Cipher.getInstance("twofish");

// initialize the cipher with the key
cipher.init(Cipher.ENCRYPT_MODE, sk);

byte[] encrypted = cipher.doFinal(toEncrypt.getBytes());
0

There are 0 answers