javaencryptiontwofish

Java encryption TwoFish with Mode ECB


I am trying encrypt and encrypt using Twofish with ECB mode. I tried using the library "gnu.crypto.cipher.Twofish" but it not allow set the mode to ECB. We can use any library or code. Please help. Thanks.


Solution

  • You can use BouncyCastle, it implements the Twofish cipher

    The Cipher is implemented as a simple block cipher (effectively ECB) and you are expected to implement the mode of operation. While you require the ECB mode (are you sure??) it seems you don't have to do much more

        Security.addProvider(new BouncyCastleProvider());
        SecretKey sKey = new SecretKeySpec(Hex.decode("8ff6d560edfd395f3a1cbee18bcce3ac"), "Twofish");
        Cipher cipher = Cipher.getInstance("Twofish/ECB/NoPadding","BC");