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);
}
}
こんにちはLuk2302、私はアルゴリズムが存在することを知っていますが、私は今日それを聞いています。 – toto
https://en.wikipedia.org/wiki/Twofish – toto
あなたの側からお試しいただけますか? キーを使用する例:dff60ebc093d5d12d90968cee4d55167とtext:09/10/14 base64への暗号化結果は次のようにする必要があります:jqcPVMd5ykivknralaM0LA == – toto