Hack6500
Hack6500
2016-03-09 08:43

(C#转JAVA)DES加密解密问题 。带入整8B加密数据, JAVA写的总是比C#写的多出来8B

1
  • c#
  • 加密

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条回答