2017-11-24 3 views
-2

TWOFISHを使用して暗号化と復号化を試みています。 は、私はエラーを受け取っ:スレッド "メイン" java.security.NoSuchAlgorithmExceptionで例外:twofishですのKeyGeneratorは利用できませんTwofishによる暗号化/復号化

マイコード:

public class TWOFISH { 

    public static byte[] encrypt(String toEncrypt, String key) throws Exception { 
     // create a binary key from the argument key (seed) 
     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); 

     // enctypt! 
     byte[] encrypted = cipher.doFinal(toEncrypt.getBytes()); 

     return encrypted; 
    } 

    public static String decrypt(byte[] toDecrypt, String key) throws Exception { 
     // create a binary key from the argument key (seed) 
     SecureRandom sr = new SecureRandom(key.getBytes()); 
     KeyGenerator kg = KeyGenerator.getInstance("twofish"); 
     kg.init(sr); 
     SecretKey sk = kg.generateKey(); 

     // do the decryption with that key 
     Cipher cipher = Cipher.getInstance("twofish"); 
     cipher.init(Cipher.DECRYPT_MODE, sk); 
     byte[] decrypted = cipher.doFinal(toDecrypt); 

     return new String(decrypted); 
    } 
} 
+0

こんにちはLuk2302、私はアルゴリズムが存在することを知っていますが、私は今日それを聞いています。 – toto

+0

https://en.wikipedia.org/wiki/Twofish – toto

+0

あなたの側からお試しいただけますか? キーを使用する例:dff60ebc093d5d12d90968cee4d55167とtext:09/10/14 base64への暗号化結果は次のようにする必要があります:jqcPVMd5ykivknralaM0LA == – toto

答えて

2
KeyGenerator kg = KeyGenerator.getInstance(String algorithm); 

https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyGenerator

によると、

が受け入れられましたStringパラの値メーターalgorithmには"twofish"が含まれていません。

+0

https://en.wikipedia.org/wiki/Twofish – toto

+1

@toto:数多くの暗号化アルゴリズムがあります世界では、オラクルのプロバイダはこれらすべてをサポートしておらず、TwoFishもサポートしていません。 –