问题描述
- (C#转JAVA)DES加密解密问题 。带入整8B加密数据, JAVA写的总是比C#写的多出来8B 1C
- C#
private byte[] CSharpEncryptByte(byte[] InputByte byte[] sKey)
{
DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Padding = PaddingMode.Zeros; DES.Key = sKey; DES.IV = new byte[] { 0 0 0 0 0 0 0 0 }; ICryptoTransform desencrypt = DES.CreateEncryptor(); byte[] result = desencrypt.TransformFinalBlock(InputByte 0 InputByte.Length); return result;
}
JAVA
public static byte[] JavaEncryptByte(byte[] InputByte byte[] bKey)
throws Exception
{
byte[] ivdata = new byte[]{0 0 0 0 0 0 0 0};
IvParameterSpec spec = new IvParameterSpec(ivdata);
SecretKeySpec keySpec = new SecretKeySpec(bKeyDES"");
Cipher cipherex = Cipher.getInstance(""DES/CBC/ZeroBytePadding"");
cipherex.init(Cipher.ENCRYPT_MODE keySpec spec);
byte[] encdata = cipherex.doFinal(InputByte 0 InputByte.length);
return encdata;
}
解决方案
试试看ECB模式,DES/ECB/ZeroBytePadding
时间: 2024-10-06 23:56:02