asp.net DES 暗号化および復号化コードの一部

怪我咯
リリース: 2017-03-30 11:37:43
オリジナル
1679 人が閲覧しました

//暗号化

 public string DesEncrypt(string strText, string strEncrKey) 
  { 
   byte[] byKey=null; 
   byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; 
   try 
   { 
    byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0,8)); 
    DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
    byte[] inputByteArray =System.Text.Encoding.UTF8.GetBytes(strText); 
    MemoryStream ms = new MemoryStream(); 
    CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ; 
    cs.Write(inputByteArray, 0, inputByteArray.Length); 
    cs.FlushFinalBlock(); 
    return Convert.ToBase64String(ms.ToArray()); 
   } 
   catch(System.Exception error) 
   { 
    MessageBox.Show(error.Message); 
    return "error:" +error.Message+"/r"; 
   } 
  }
ログイン後にコピー

//復号化

 public string DesDecrypt(string strText,string sDecrKey) 
  { 
   byte[] byKey = null; 
   byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; 
   byte[] inputByteArray = new Byte[strText.Length]; 
   try 
   { 
    byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0,8)); 
    DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
    inputByteArray = Convert.FromBase64String(strText); 
    MemoryStream ms = new MemoryStream(); 
    CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write); 
    cs.Write(inputByteArray, 0, inputByteArray.Length); 
    cs.FlushFinalBlock(); 
    System.Text.Encoding encoding = new System.Text.UTF8Encoding(); 
    return encoding.GetString(ms.ToArray()); 
   } 
   catch(System.Exception error) 
   { 
    MessageBox.Show(error.Message); 
    return "error:"+error.Message+"/r"; 
   } 
  }
ログイン後にコピー


以上がasp.net DES 暗号化および復号化コードの一部の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!