C# 加密算法SHA

using System;
using System.Security.Cryptography;
using System.Text;

namespace XiaoFeng.Cryptography
{
    /// 
    /// SHA加密解密
    /// version : 1.0.0
    /// 
    public class SHACrypto
    {
        #region 构造器
        /// 
        /// 无参构造器
        /// 
        public SHACrypto()
        {
            this.encoding = Encoding.Default;
        }
        #endregion

        #region 属性
        /// 
        /// 编码
        /// 
        public Encoding encoding { get; set; }
        /// 
        /// 静态方法
        /// 
        public static SHACrypto SHA { get { return new SHACrypto(); } }
        #endregion

        #region 方法
        /// 
        /// SHA加密
        /// 
        /// 明文
        /// 
        public string SHA1Encrypt(string data)
        {
            return Convert.ToBase64String(new SHA1CryptoServiceProvider().ComputeHash(data.GetBytes(this.encoding)));
        }
        /// 
        /// SHA256加密
        /// 
        /// 明文
        /// 
        public string SHA256Encrypt(string data)
        {
            return Convert.ToBase64String(new SHA256CryptoServiceProvider().ComputeHash(data.GetBytes(this.encoding)));
        }
        /// 
        /// SHA384加密
        /// 
        /// 明文
        /// 
        public string SHA384Encrypt(string data)
        {
            return Convert.ToBase64String(new SHA384CryptoServiceProvider().ComputeHash(data.GetBytes(this.encoding)));
        }
        /// 
        /// SHA512加密
        /// 
        /// 明文
        /// 
        public string SHA512Encrypt(string data)
        {
            return Convert.ToBase64String(new SHA512CryptoServiceProvider().ComputeHash(data.GetBytes(this.encoding)));
        }
        #endregion
    }
}

你可能感兴趣的:(加密算法)