예제 #1
0
 /// <summary>
 /// 解密数据
 /// </summary>
 /// <returns>The data.</returns>
 /// <param name="dataToDecrypt">Data to decrypt.</param>
 public string DecryptData(string dataToDecrypt)
 {
     //给密文解密用FromBase64String
     byte[] dataToDecryptArray = Convert.FromBase64String(dataToDecrypt);
     byte[] dataAfterDecryptArray = GlobalDataHelper.DataEncryptAlgorithm().CreateDecryptor()
     .TransformFinalBlock(dataToDecryptArray, 0, dataToDecryptArray.Length);
     return Encoding.UTF8.GetString(dataAfterDecryptArray);
 }
예제 #2
0
 /// <summary>
 /// 加密数据
 /// </summary>
 /// <returns>The data.</returns>
 /// <param name="dataToEncrypt">Data to encrypt.</param>
 public string EncryptData(string dataToEncrypt)
 {
     //给明文加密用GetBytes
     byte[] dataToEncryptArray = Encoding.UTF8.GetBytes(dataToEncrypt);
     byte[] dataAfterEncryptArray = GlobalDataHelper.DataEncryptAlgorithm().CreateEncryptor()
     .TransformFinalBlock(dataToEncryptArray, 0, dataToEncryptArray.Length);
     return Convert.ToBase64String(dataAfterEncryptArray, 0, dataAfterEncryptArray.Length);
 }