国产探花免费观看_亚洲丰满少妇自慰呻吟_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
    }
    }



    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 汉阴县| 白河县| 清新县| 巴林左旗| 大姚县| 祁连县| 伊吾县| 岑溪市| 克什克腾旗| 江川县| 黑山县| 宜黄县| 沅陵县| 南开区| 泊头市| 镇沅| 舟曲县| 新竹市| 宕昌县| 丹巴县| 新化县| 阳高县| 河池市| 交口县| 惠来县| 元朗区| 铜山县| 梓潼县| 怀仁县| 依兰县| 高清| 调兵山市| 高州市| 美姑县| 江口县| 美姑县| 珲春市| 灵寿县| 南平市| 宽城| 连平县|