wbc3112762
qweqaasd2
2017-09-13 16:26

求大神写一个UnEncode

10
  • c#
  • encode
  • 解密
  • unencode
  • 加密

这里是一个加密的方法,求大神写一个解密方法。
public static string Encode(string pSource, string pKey)
{
bool flag;
string s2;

        StringBuilder stringBuilder = new StringBuilder();
        pKey = pKey.PadRight(8, '8');
        DESCryptoServiceProvider descryptoServiceProvider = new DESCryptoServiceProvider();
        try
        {
            byte[] bArr1 = Encoding.ASCII.GetBytes(pKey);
            byte[] bArr2 = Encoding.ASCII.GetBytes(pKey);
            byte[] bArr3 = Encoding.UTF8.GetBytes(pSource);
            descryptoServiceProvider.Mode = CipherMode.CBC;
            descryptoServiceProvider.Key = bArr1;
            descryptoServiceProvider.IV = bArr2;
            string s1 = "";
            MemoryStream memoryStream = new MemoryStream();
            try
            {
                CryptoStream cryptoStream = new CryptoStream(memoryStream, descryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
                try
                {
                    cryptoStream.Write(bArr3, 0, bArr3.Length);
                    cryptoStream.FlushFinalBlock();
                    s1 = Convert.ToBase64String(memoryStream.ToArray());
                }
                finally
                {
                    flag = cryptoStream == null;
                    if (!flag)
                        cryptoStream.Dispose();
                }
            }
            finally
            {
                flag = memoryStream == null;
                if (!flag)
                    memoryStream.Dispose();
            }
            s2 = s1;
        }
        finally
        {
            flag = descryptoServiceProvider == null;
            if (!flag)
                descryptoServiceProvider.Dispose();
        }
        return s2;
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐