namespace CounsellorBL.Helper { using OT.COM.Encryption; using OT.COM.LogisticsUtil; using System; public static class EncryptHelper { private static readonly byte[] _Key = System.Text.Encoding.Unicode.GetBytes(Util.GetSettingString("KEY")); private static readonly byte[] _IV = System.Text.Encoding.Unicode.GetBytes(Util.GetSettingString("IV")); private static readonly AES _aes = new AES(); /// /// 函式名稱:Encrypt /// 函式說明:加密API /// 起始作者:Hercules /// 起始日期:2016/06/17 /// 最新修改人: Hercules /// 最新修日期: 2016/06/17 /// /// 明碼 /// 暗碼 /// 錯誤訊息,若成功則為Null public static string Encrypt(string i_sPlaintext, out string o_sCiphertext) { string sMsg = null; string sRes = null; try { do { byte[] baRes = _aes.EncryptStringToByte( i_sPlaintext, _Key, _IV); sRes = Convert.ToBase64String(baRes); } while (false); } finally { o_sCiphertext = sRes; } return sMsg; } /// /// 函式名稱:Decrypt /// 函式說明:解密API /// 起始作者:Hercules /// 起始日期:2016/06/17 /// 最新修改人: Hercules /// 最新修日期: 2016/06/17 /// /// 暗碼 /// 明碼 /// 錯誤訊息,若成功則為Null public static string Decrypt(string i_sCiphertext, out string o_sPlaintext) { string sMsg = null; string sRes = null; try { do { byte[] baCiphertext = Convert.FromBase64String(i_sCiphertext); sRes = _aes.DecryptByteToString( baCiphertext, _Key, _IV); } while (false); } finally { o_sPlaintext = sRes; } return sMsg; } } }