2 hack6500 Hack6500 于 2016.03.09 16:43 提问

(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(bKey, "DES");
Cipher cipherex = Cipher.getInstance("DES/CBC/ZeroBytePadding");
cipherex.init(Cipher.ENCRYPT_MODE, keySpec, spec);
byte[] encdata = cipherex.doFinal(InputByte, 0, InputByte.length);
return encdata;
}

1个回答

sx011966
sx011966   2016.03.10 09:54

试试看ECB模式,DES/ECB/ZeroBytePadding

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!