当前位置:  开发笔记 > 编程语言 > 正文

Decrypt/Decrypt阿拉伯字符串

如何解决《Decrypt/Decrypt阿拉伯字符串》经验,为你挑选了1个好方法。

如何在C#中加密/解密阿拉伯语文本

    public static string Encrypt(string pDataToEncrypt)
    {

        ASCIIEncoding textConverter = new ASCIIEncoding();
        RijndaelManaged myRijndael = new RijndaelManaged();
        byte[] toEncrypt;

        ICryptoTransform encryptor = myRijndael.CreateEncryptor(key, IV);

        MemoryStream msEncrypt = new MemoryStream();
        CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor,            CryptoStreamMode.Write);

        toEncrypt = textConverter.GetBytes(pDataToEncrypt);

        csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
        csEncrypt.FlushFinalBlock();

        return Convert.ToBase64String(msEncrypt.GetBuffer(), 0, (int)msEncrypt.Length);
    }

    public static string Decrypt(string pDataToDecrypt)
    {
        RijndaelManaged myRijndael = new RijndaelManaged();
        byte[] fromEncrypt;

        //Encoding asciiEncoding = Encoding.ASCII;

        fromEncrypt = Convert.FromBase64String(pDataToDecrypt);
        ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);

        MemoryStream msDecrypt = new MemoryStream(fromEncrypt, 0, fromEncrypt.Length);
        CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
        StreamReader sr = new StreamReader(csDecrypt);

        return sr.ReadToEnd();

    }

当我尝试加密其返回"????" 问号

提前致谢



1> AminSojoudi..:

使用

UnicodeEncoding() 

代替

ASCIIEncoding()

推荐阅读
罗文彬2502852027
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有