我正在实施 DES - CBC。我对做什么cipher.init
和做什么cipher.update
感到困惑cipher.dofinal
。我只是使用 init 来设置密钥并dofinal
获得结果。我不使用更新。那是对的吗?
使用UTF-8和ASCII编码时,结果有何不同?
这是我的代码:
byte[] ciphertext;
Cipher enc = Cipher.getInstance("DES/CBC/PKCS5Padding");
enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES"), new IvParameterSpec(vector));
// Is this the complete ciphertext?
ciphertext = encrypt.doFinal(data.getbytes("UTF-8"));