0

在我知道密码的情况下,如何使用 C# 解密这个 XML 文件?

<EncryptedData xmlns="w3.org/2001/04/xmlenc#"; Type="w3.org/2001/04/xmlenc#Element"; Salt="Gnk/DB61AQ==" IV="iYcfV0NOGy0="> 
<EncryptionMethod Algorithm="w3.org/2001/04/xmlenc#tripledes-cbc"; /> 
<CipherData>
 <CipherValue>/TtgJ46P9L23ZeGt67n+2OZGXoHiGWcUAWE8CdN1Z2aiF40fAg6DfBWGx62RB7Botxr‌​w+f1Jf1CtR10iMLw0iz+VIcbaPFZj5ZfCm3aDeDLbnwXdb7mIdzNtF/5EOjNph/kPz7PxcUlAOUvsLLmj‌​Gtx92EhWL6KpXufKahnRiwLuZLNc</CipherValue>
</CipherData>
</EncryptedData>

我试过了

public static string Decryption(string CypherText, string key) 
{
    byte[] b = Convert.FromBase64String(CypherText); 
    TripleDES des = CreateDES(key);
    ICryptoTransform ct = des.CreateDecryptor();
    byte[] output = ct.TransformFinalBlock(b, 0, b.Length); 
    return Encoding.Unicode.GetString(output); 
} 

但是发生了异常

byte[] 输出 = ct.TransformFinalBlock(b, 0, b.Length); 不良数据

4

1 回答 1

0

http://www.deltasblog.co.uk/code-snippets/basic-encryptiondecryption-c/

  byte[] inputArray = Convert.FromBase64String(input);
          TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
          tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key);
          tripleDES.Mode = CipherMode.ECB;
          tripleDES.Padding = PaddingMode.PKCS7;
          ICryptoTransform cTransform = tripleDES.CreateDecryptor();
          byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
          tripleDES.Clear();
          return UTF8Encoding.UTF8.GetString(resultArray);
于 2013-02-13T09:50:35.770 回答