3Des实际上只是3个单独的DES操作,每个操作都需要一个8字节的密钥。这需要24字节的密钥..但是一些实现支持16字节密钥,其中前8个字节在场景后“自动重复”。有的实现可能不支持这一点。你怎么能通过重复前8个字节来自己做 - 这样的事情:
public static byte[] encrypt3DESECB(byte[] keyBytes, byte[] dataBytes) {
try {
if (keyBytes.length == 16) { // short key ? .. extend to 24 byte key
byte[] tmpKey = new byte[24];
System.arraycopy(keyBytes, 0, tmpKey, 0, 16);
System.arraycopy(keyBytes, 0, tmpKey, 16, 8);
keyBytes = tmpKey;
}
SecretKeySpec newKey = new SecretKeySpec(keyBytes, "DESede");
...
...