国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

一個可以用來加密/解密的類

2024-07-21 02:24:33
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 可以用來加/解密數據庫用戶、密碼等

    using system;
    using system.io;
    using system.text;
    using system.security.cryptography;

    namespace common
    {
    /// <summary>
    /// securityservice 的摘要說明。
    /// </summary>
    public class securityservice
    {
    static protected byte[] bytekey = {125, 14, 45, 67, 112, 79, 77, 99, 37, 104, 13, 9, 118, 51, 87, 108};
    static protected byte[] byteiv = {86, 19, 79, 15, 72, 58, 117, 45};
    static public string symmetricencrypt(string splaintext)
    {
    byte[] byteplaintext;
    memorystream encryptedstream;
    icryptotransform encryptor;
    cryptostream thecryptostream;
    if(splaintext=="") return "";
    byteplaintext = encoding.ascii.getbytes(splaintext);
    encryptedstream = new memorystream(splaintext.length);
    encryptor = getencryptor();
    thecryptostream = new cryptostream(encryptedstream, encryptor, cryptostreammode.write);
    thecryptostream.write(byteplaintext, 0, byteplaintext.length);
    thecryptostream.flushfinalblock();
    thecryptostream.close();

    return convert.tobase64string(encryptedstream.toarray());

    }//end function

    static public string symmetricdecrypt(string sencryptedtext)
    {
    byte[] byteencrypted;
    memorystream plaintextstream;
    icryptotransform decryptor;
    cryptostream thecryptostream;

    if (sencryptedtext == "") return "";

    byteencrypted = convert.frombase64string(sencryptedtext.trim());
    plaintextstream = new memorystream(sencryptedtext.length);
    decryptor = getdecryptor();
    thecryptostream = new cryptostream(plaintextstream, decryptor, cryptostreammode.write);

    thecryptostream.write(byteencrypted, 0, byteencrypted.length);
    thecryptostream.flushfinalblock();
    thecryptostream.close();

    return encoding.ascii.getstring(plaintextstream.toarray());

    }//end function

    static private icryptotransform getencryptor()
    {
    rc2cryptoserviceprovider cryptoprovider = new rc2cryptoserviceprovider();
    cryptoprovider.mode = ciphermode.cbc;
    return cryptoprovider.createencryptor(bytekey, byteiv);

    }//end function

    static private icryptotransform getdecryptor()
    {
    rc2cryptoserviceprovider cryptoprovider = new rc2cryptoserviceprovider();
    cryptoprovider.mode = ciphermode.cbc;
    return cryptoprovider.createdecryptor(bytekey, byteiv);

    }//end function
    }
    }



    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 南康市| 石嘴山市| 开鲁县| 本溪| 黄平县| 乐陵市| 武义县| 镇原县| 临沂市| 九寨沟县| 理塘县| 晋城| 云和县| 宁明县| 从江县| 疏勒县| 琼海市| 天台县| 甘肃省| 青浦区| 鄢陵县| 密云县| 潍坊市| 仲巴县| 尚志市| 许昌县| 常宁市| 资阳市| 陇川县| 湘潭市| 绵阳市| 合山市| 高青县| 灵武市| 册亨县| 交城县| 甘德县| 桐乡市| 南华县| 上林县| 延庆县|