画像内のテキストを暗号化するステガノグラフィ システムを作成しています。画像に埋め込む前に、テキストも暗号化することにしました。ステガノグラフィ アルゴリズムは、文字列の入力/出力で動作します。
私の気まぐれにより、DES および AES アルゴリズムを使用しようとしましたが、上記の例外に遭遇しました。たとえば、AES アルゴリズムの暗号化/復号化方法を示します。
public static byte[] encryptText(String plainText,SecretKey secKey) throws Exception{
// AES defaults to AES/ECB/PKCS5Padding in Java 7
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] byteCipherText = aesCipher.doFinal(plainText.getBytes());
return byteCipherText;}
public static String decryptText(byte[] byteCipherText, SecretKey secKey) throws Exception {
// AES defaults to AES/ECB/PKCS5Padding in Java 7
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.DECRYPT_MODE, secKey);
byte[] bytePlainText = aesCipher.doFinal(byteCipherText);
return new String(bytePlainText);
}
そして、ここに呼び出しがあります(暗号化側):
//sending the text to encrypt using AES algorithm
byte[] cipherText = new AES_Algorithm().encrypt(messageDesc.getText(), key);
//converting into a String to encrypt using Steganography
newStringtoEncrypt = new String (cipherText);
そして、ここに呼び出しがあります(復号化側) - THE EXCEPTION:
//AES encrypted String after the Steganography's decryption
String decMessage = dec.decode(path, name);
//converting the String to byte []
byte [] byteArray = decMessage.getBytes();
try{
//HERE IS WHERE I GET THE EXCEPTION
//sending the byte array to decryption
String original = AES_Algorithm().decrypt(byteArray, key);
問題はどこだ?
キーは似ており、バイト配列も同様です(シーケンスを印刷して確認しました)-しかし、復号化アルゴリズムを使用するときにgetBytes()
、文字列から変換するために使用できないと言われました。byteArray
AES/DES