我正在编写一个加密图像中的文本的隐写术系统 - 我决定在将文本嵌入图片之前也要对其进行加密。隐写算法适用于字符串输入/输出。
由于我的心血来潮,我一直在尝试使用 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);
这是调用(解密方面)-例外:
//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
解密算法的时间。