Triple DES Encrypt C# - Decrypt in Java

后端 未结 3 1836
孤独总比滥情好
孤独总比滥情好 2021-01-07 14:45

I\'m getting a Triple DES decrypted string from the clients server, which has been coded in c# (see below):

using System.IO;
using System;
using System.Secur         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 15:48

    In your C# code, you use ASCII:

    bytClearText = ASCIIEncoding.ASCII.GetBytes(strClearText);
    

    While in Java you use UNICODE:

    byte[] encryptKeyBytes = encryptKey.getBytes(UNICODE_FORMAT);
    

    Try to change your C# to use UNICODE or your java code to use ASCII.

    Also, since the C# is padding the output :

    strEncryptedChar = strEncryptedChar.PadLeft(2, Convert.ToChar("0"));
    

    You probably must check to remove all the '00' in the crypted string, so 1D30CC3DE1641D7F5E821D13FC1200C3 will become 1D30CC3DE1641D7F5E821D13FC12C3

    (you must check if it's in the boundaries of an hex expression: 1C01A1 should probably be modified since it got a padding on the second Hexa 1C 01 A1: 1C1A1

提交回复
热议问题