我正在研究DES加密算法。我能够将纯文本加密为密文,但我无法将密文解密回正常的纯文本。
我应该使用哪种转换器?
以下是我的加密方法中使用的代码:
public static String encryptString(String src) throws Exception {
String dst = "";
SecretKey secret_key = KeyGenerator.getInstance("DES").generateKey();
AlgorithmParameterSpec alogrithm_specs = new IvParameterSpec(initialization_vector);
encrypt = Cipher.getInstance("DES/CBC/PKCS5Padding");
encrypt.init(Cipher.ENCRYPT_MODE, secret_key, alogrithm_specs);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CipherOutputStream cout = new CipherOutputStream(baos,encrypt);
cout.write(src.getBytes());
cout.flush(); //ByteOutputStream -> Write Encryption Text
cout.close();
dst = DatatypeConverter.printHexBinary(baos.toByteArray());
return dst;
}