(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个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐