TripleDES Encrypting in C# and PHP not coming out the same (PKCS7, ECB)?

后端 未结 4 1996
眼角桃花
眼角桃花 2021-01-14 11:56

I\'ve spent a couple hours now trying to figure this out, but I just can\'t get it to work. I\'ve got a C# encryption routine that I need to match in php. I can\'t change

4条回答
  •  太阳男子
    2021-01-14 12:27

    I found a solution, check this link, may help you. http://sanity-free.com/131/triple_des_between_php_and_csharp.html

    And here is the decrypt function just in case:

        public static string Decrypt(string cypherString)
        {
    
            byte[] key = Encoding.ASCII.GetBytes("icatalogDR0wSS@P6660juht");
            byte[] iv = Encoding.ASCII.GetBytes("iCatalog");
            byte[] data = Convert.FromBase64String(cypherString);
            byte[] enc = new byte[0];
            TripleDES tdes = TripleDES.Create();
            tdes.IV = iv;
            tdes.Key = key;
            tdes.Mode = CipherMode.CBC;
            tdes.Padding = PaddingMode.Zeros;
            ICryptoTransform ict = tdes.CreateDecryptor();
            enc = ict.TransformFinalBlock(data, 0, data.Length);
            return UTF8Encoding.UTF8.GetString(enc, 0, enc.Length);
        }
    

提交回复
热议问题