public string Encrypt(EncryptInfo model) { //Rijndael rijndael = Rijndael.Create(); //rijndael.IV = model.Encode.GetBytes(model.Iv); //rijndael.Key = model.Encode.GetBytes(model.Key); //Byte[] bytes = model.Encode.GetBytes(model.Source); //string result = ""; //using (ICryptoTransform transform = rijndael.CreateEncryptor()) //{ // byte[] output = transform.TransformFinalBlock(bytes, 0, bytes.Length); // result = Convert.ToBase64String(output); //} //return result; Byte[] plainBytes = model.Encode.GetBytes(model.Source); Byte[] bKey = new Byte[32]; Array.Copy(model.Encode.GetBytes(model.Key.PadRight(bKey.Length)), bKey, bKey.Length); Byte[] bVector = new Byte[16]; Array.Copy(model.Encode.GetBytes(model.Iv.PadRight(bVector.Length)), bVector, bVector.Length); Byte[] Cryptograph = null; Rijndael Aes = Rijndael.Create(); using (MemoryStream Memory = new MemoryStream()) { using (CryptoStream Encryptor = new CryptoStream(Memory, Aes.CreateEncryptor(bKey, bVector), CryptoStreamMode.Write)) { Encryptor.Write(plainBytes, 0, plainBytes.Length); Encryptor.FlushFinalBlock(); Cryptograph = Memory.ToArray(); } } return(Convert.ToBase64String(Cryptograph)); }
public string Encrypt(EncryptInfo model) { byte[] result = model.Encode.GetBytes(model.Source); MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); return(BitConverter.ToString(output).Replace("-", "")); }
public string Encrypt(EncryptInfo model) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); string result = BitConverter.ToString(md5.ComputeHash(model.Encode.GetBytes(model.Source)), 4, 8); result = result.Replace("-", ""); return(result); }
public string Dencrypt(EncryptInfo model) { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] cipherbytes; rsa.FromXmlString(model.Key); cipherbytes = rsa.Decrypt(Convert.FromBase64String(model.Source), false); return(model.Encode.GetString(cipherbytes)); }
public string Encrypt(EncryptInfo model) { SHA1 sha1 = new SHA1CryptoServiceProvider(); byte[] bytes = model.Encode.GetBytes(model.Source); byte[] output = sha1.ComputeHash(bytes); string result = BitConverter.ToString(output).Replace("-", ""); return(result); }
public string Encrypt(EncryptInfo model) { TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); DES.Key = model.Encode.GetBytes(model.Key); DES.Mode = CipherMode.ECB; ICryptoTransform DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = model.Encode.GetBytes(model.Source); return(Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))); }
public string Dencrypt(EncryptInfo model) { TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); DES.Key = model.Encode.GetBytes(model.Key); DES.Mode = CipherMode.ECB; DES.Padding = System.Security.Cryptography.PaddingMode.PKCS7; ICryptoTransform DESDecrypt = DES.CreateDecryptor(); byte[] Buffer = Convert.FromBase64String(model.Source); return(model.Encode.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))); }
public string Check(EncryptInfo model) { StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(model.Key)) { sb.Append("秘钥不能为空"); } else if (model.Key.Length != 24) { sb.Append("秘钥长度必须为24"); } return(sb.ToString()); }
public string Dencrypt(EncryptInfo model) { string result = ""; byte[] byKey = model.Encode.GetBytes(model.Key); byte[] byIV = model.Encode.GetBytes(model.Iv); byte[] byEnc = Convert.FromBase64String(model.Source); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); using (MemoryStream ms = new MemoryStream(byEnc)) using (CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read)) using (StreamReader sr = new StreamReader(cst)) result = sr.ReadToEnd(); return(result); }
public string Dencrypt(EncryptInfo model) { byte[] bytesIV = model.Encode.GetBytes(model.Iv); RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider(); byte[] bytesInput = Convert.FromBase64String(model.Source); using (MemoryStream ms = new MemoryStream()) using (CryptoStream cs = new CryptoStream(ms, rc2.CreateDecryptor(Encoding.Default.GetBytes(model.Key), bytesIV), CryptoStreamMode.Write)) { cs.Write(bytesInput, 0, bytesInput.Length); cs.FlushFinalBlock(); string result = model.Encode.GetString(ms.ToArray()); return(result); } }
public string Check(EncryptInfo model) { StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(model.Key)) { sb.Append("秘钥不能为空,"); } else if (model.Key.Length != 32) { sb.Append("秘钥长度必须为32,"); } if (!string.IsNullOrEmpty(model.Iv) && model.Iv.Length != 16) { sb.Append("向量长度必须为16,"); } return(sb.ToString()); }
public string Dencrypt(EncryptInfo model) { //Rijndael rijndael = Rijndael.Create(); //rijndael.Key = model.Encode.GetBytes(model.Key); //rijndael.IV = model.Encode.GetBytes(model.Iv); //byte[] bytes = model.Encode.GetBytes(model.Source); //using (ICryptoTransform transform2 = rijndael.CreateDecryptor()) //{ // byte[] decryption = transform2.TransformFinalBlock(bytes, 0, bytes.Length); // return model.Encode.GetString(decryption); //} Byte[] encryptedBytes = Convert.FromBase64String(model.Source); Byte[] bKey = new Byte[32]; Array.Copy(model.Encode.GetBytes(model.Key.PadRight(bKey.Length)), bKey, bKey.Length); Byte[] bVector = new Byte[16]; Array.Copy(model.Encode.GetBytes(model.Iv.PadRight(bVector.Length)), bVector, bVector.Length); Byte[] original = null; Rijndael Aes = Rijndael.Create(); using (MemoryStream Memory = new MemoryStream(encryptedBytes)) { using (CryptoStream Decryptor = new CryptoStream(Memory, Aes.CreateDecryptor(bKey, bVector), CryptoStreamMode.Read)) { using (MemoryStream originalMemory = new MemoryStream()) { Byte[] Buffer = new Byte[1024]; Int32 readBytes = 0; while ((readBytes = Decryptor.Read(Buffer, 0, Buffer.Length)) > 0) { originalMemory.Write(Buffer, 0, readBytes); } original = originalMemory.ToArray(); } } } return(model.Encode.GetString(original)); }
public string Encrypt(EncryptInfo model) { string result = ""; byte[] byKey = model.Encode.GetBytes(model.Key); byte[] byIV = model.Encode.GetBytes(model.Iv); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize; using (MemoryStream ms = new MemoryStream()) using (CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write)) using (StreamWriter sw = new StreamWriter(cst)) { sw.Write(model.Source); sw.Flush(); cst.FlushFinalBlock(); sw.Flush(); result = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); } return(result); }
public string Encrypt(EncryptInfo model) { return(Convert.ToBase64String(model.Encode.GetBytes(model.Source))); }
public string Check(EncryptInfo model) { return(""); }
public string Dencrypt(EncryptInfo model) { throw new Exception("该方法没有实现方式"); }
public string Dencrypt(EncryptInfo model) { return(HttpUtility.UrlDecode(model.Source, model.Encode)); }
public string Dencrypt(EncryptInfo model) { return(model.Encode.GetString(Convert.FromBase64String(model.Source))); }