<i id='MCw5k'><tr id='MCw5k'><dt id='MCw5k'><q id='MCw5k'><span id='MCw5k'><b id='MCw5k'><form id='MCw5k'><ins id='MCw5k'></ins><ul id='MCw5k'></ul><sub id='MCw5k'></sub></form><legend id='MCw5k'></legend><bdo id='MCw5k'><pre id='MCw5k'><center id='MCw5k'></center></pre></bdo></b><th id='MCw5k'></th></span></q></dt></tr></i><div id='MCw5k'><tfoot id='MCw5k'></tfoot><dl id='MCw5k'><fieldset id='MCw5k'></fieldset></dl></div>

      <bdo id='MCw5k'></bdo><ul id='MCw5k'></ul>
  • <small id='MCw5k'></small><noframes id='MCw5k'>

    <tfoot id='MCw5k'></tfoot>

    1. <legend id='MCw5k'><style id='MCw5k'><dir id='MCw5k'><q id='MCw5k'></q></dir></style></legend>
      1. 在 Coldfusion 中加密并在 C# 中解密

        时间:2023-06-05

        <small id='BYBXh'></small><noframes id='BYBXh'>

          <bdo id='BYBXh'></bdo><ul id='BYBXh'></ul>

            1. <tfoot id='BYBXh'></tfoot>
                <tbody id='BYBXh'></tbody>
              • <i id='BYBXh'><tr id='BYBXh'><dt id='BYBXh'><q id='BYBXh'><span id='BYBXh'><b id='BYBXh'><form id='BYBXh'><ins id='BYBXh'></ins><ul id='BYBXh'></ul><sub id='BYBXh'></sub></form><legend id='BYBXh'></legend><bdo id='BYBXh'><pre id='BYBXh'><center id='BYBXh'></center></pre></bdo></b><th id='BYBXh'></th></span></q></dt></tr></i><div id='BYBXh'><tfoot id='BYBXh'></tfoot><dl id='BYBXh'><fieldset id='BYBXh'></fieldset></dl></div>
                <legend id='BYBXh'><style id='BYBXh'><dir id='BYBXh'><q id='BYBXh'></q></dir></style></legend>
                1. 本文介绍了在 Coldfusion 中加密并在 C# 中解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这里是coldfusion中用来加密的代码

                  Here is the code used to encrypt in coldfusion

                  <cfset strBase64Value = encrypt(strValue,24 character key,AES) />
                  

                  它正在生成像 714FEA9A9A2184769CA49D5133F08580 这样的加密值,考虑到它只是大写和数字,这对我来说似乎很奇怪.

                  It is generating encrypted values like 714FEA9A9A2184769CA49D5133F08580 which seems odd to me considering it is only uppercase and numbers.

                  我应该使用什么 C# 库来正确解密它?

                  What C# library should I use to properly decrypt it ?

                  同时查看此信息,貌似默认使用UUEncode算法进行编码.

                  Also looking at this information, it seems that by default it uses the UUEncode algorithm to encode.

                  我应该要求加密器使用 Base64 作为编码参数吗?

                  Should I ask the encrypter to use Base64 as encoding parameter ?

                  推荐答案

                  它正在生成像 714FEA9A9A2184769CA49D5133F08580

                  然后他们使用Hex",而不是默认的UUEncode".hex"或base64"都可以.只要你们都同意编码,这并不重要.

                  Then they are using "Hex", not the default "UUEncode". Either "hex" or "base64" is fine. As long as you both agree upon the encoding, it does not really matter.

                  您可以使用 RijndaelManaged 来解密字符串.但是,ColdFusion 和 C# 的默认加密设置略有不同.使用加密功能:

                  You can use RijndaelManaged to decrypt the strings. However, the default encryption settings for ColdFusion and C# differ slightly. With the encrypt function:

                  • AES"是AES/ECB/PKCS5Padding"的缩写
                  • ECB"模式不使用 IV
                  • 密钥字符串始终采用 base64 编码

                  注意: 尽管名称不同,但对于 SUN 提供程序,PKCS5Padding (CF/Java) 对应于 PaddingMode.PKCS7 (C#).如本帖所述,"... Java 中的 SUN 提供程序指示 [s] PKCS#5 应该在哪里使用 PKCS#7 - "PKCS5Padding" 应该是 "PKCS7Padding".这是从只有 8 字节块密码的时候的遗产例如(三重)DES 对称密码可用."

                  NB: Despite the name difference, for the SUN provider, PKCS5Padding (CF/Java) corresponds to PaddingMode.PKCS7 (C#). As mentioned in this thread, the "... SUN provider in Java indicate[s] PKCS#5 where PKCS#7 should be used - "PKCS5Padding" should have been "PKCS7Padding". This is a legacy from the time that only 8 byte block ciphers such as (triple) DES symmetric cipher were available."

                  因此,您需要确保调整 C# 设置以匹配.考虑到这一点,只需解码加密文本 来自 hex 和来自 base64 的密钥字符串.使用 有点难看API 中的示例,只需调整算法设置以匹配 encrypt() 函数使用的设置:

                  So you need to ensure your C# settings are adjusted to match. With that in mind, just decode the encrypted text from hex and the key string from base64. Using the slightly ugly example in the API, just adjust the algorithm settings to match those used by the encrypt() function:

                  使用 ColdFusion 加密

                  <cfscript>
                      plainText     = "Nothing to see";
                      // 128 bit key base64 encoded
                      keyInBase64   = "Y25Aju8H2P5DR8mY6B0ezg==";
                      // "AES" is short for "AES/ECB/PKCS5Padding"
                      encryptedText = encrypt(plainText, keyInBase64, "AES", "hex");
                      WriteDump( encryptedText );
                      // result: 8889EDF02F181158AAD902AB86C63951 
                  </cfscript>
                  

                  用 C# 解密

                  byte[] bytes = SomeMethodToConvertHexToBytes( encryptedText );
                  byte[] key = Convert.FromBase64String( keyInBase64 );
                  
                  string decryptedText = null;
                  
                  using (RijndaelManaged algorithm = new RijndaelManaged())
                  {
                  
                      // initialize settings to match those used by CF
                      algorithm.Mode = CipherMode.ECB;
                      algorithm.Padding = PaddingMode.PKCS7;
                      algorithm.BlockSize = 128;
                      algorithm.KeySize = 128;
                      algorithm.Key = key;
                  
                      ICryptoTransform decryptor = algorithm.CreateDecryptor();
                  
                      using (MemoryStream msDecrypt = new MemoryStream(bytes))
                      {
                          using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                          {
                             using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                             {
                  
                                 decryptedText = srDecrypt.ReadToEnd();
                             }
                          }
                      }
                  }
                  
                  Console.WriteLine("Encrypted String: {0}", encryptedText);
                  Console.WriteLine("Decrypted String: {0}", decryptedText);
                  

                  请记住,您可以(并且可能应该)调整设置,例如使用更安全的 CBC 模式 而不是 ECB.您只需要与 CF 开发人员协调这些更改.

                  Keep in mind you can (and probably should) adjust the settings, such as using the more secure CBC mode instead of ECB. You just need to coordinate those changes with the CF developer.

                  这篇关于在 Coldfusion 中加密并在 C# 中解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:ColdFusion - cfusion_encrypt() 和 cfusion_decrypt() - C# 替代 下一篇:在不同的 TFS 分支上工作时丢失 EF 代码优先迁移

                  相关文章

                  最新文章

                2. <tfoot id='Bt2HT'></tfoot>

                  <small id='Bt2HT'></small><noframes id='Bt2HT'>

                  • <bdo id='Bt2HT'></bdo><ul id='Bt2HT'></ul>
                      <legend id='Bt2HT'><style id='Bt2HT'><dir id='Bt2HT'><q id='Bt2HT'></q></dir></style></legend>
                    1. <i id='Bt2HT'><tr id='Bt2HT'><dt id='Bt2HT'><q id='Bt2HT'><span id='Bt2HT'><b id='Bt2HT'><form id='Bt2HT'><ins id='Bt2HT'></ins><ul id='Bt2HT'></ul><sub id='Bt2HT'></sub></form><legend id='Bt2HT'></legend><bdo id='Bt2HT'><pre id='Bt2HT'><center id='Bt2HT'></center></pre></bdo></b><th id='Bt2HT'></th></span></q></dt></tr></i><div id='Bt2HT'><tfoot id='Bt2HT'></tfoot><dl id='Bt2HT'><fieldset id='Bt2HT'></fieldset></dl></div>