0

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());
James Z
  • 12,209
  • 10
  • 24
  • 44
Shilpi
  • 1
  • 1
  • Perhaps your security provider does not support Twofish. what provider do you use. – RaniDevpr Dec 12 '17 at 14:28
  • 1
    Also, why use Twofish as opposed to AES? Note that Twofish designer Bruce Schneier uses AES, not Twofish—that is telling. – zaph Dec 12 '17 at 14:56
  • Thanks Dear... there is no provider, i am trying to implement it for some comparison purpose.. – Shilpi Dec 15 '17 at 10:56

0 Answers0