本文整理汇总了C#中System.Security.Cryptography.TripleDESCryptoServiceProvider.CreateDecryptor方法的典型用法代码示例。如果您正苦于以下问题:C# TripleDESCryptoServiceProvider.CreateDecryptor方法的具体用法?C# TripleDESCryptoServiceProvider.CreateDecryptor怎么用?C# TripleDESCryptoServiceProvider.CreateDecryptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.TripleDESCryptoServiceProvider
的用法示例。
在下文中一共展示了TripleDESCryptoServiceProvider.CreateDecryptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TripleDESKeyWrapDecrypt
internal static byte[] TripleDESKeyWrapDecrypt (byte[] rgbKey, byte[] rgbEncryptedWrappedKeyData) {
// Check to see whether the length of the encrypted key is reasonable
if (rgbEncryptedWrappedKeyData.Length != 32 && rgbEncryptedWrappedKeyData.Length != 40
&& rgbEncryptedWrappedKeyData.Length != 48)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KW_BadKeySize"));
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
// Assume no padding, use CBC mode
tripleDES.Padding = PaddingMode.None;
ICryptoTransform dec1 = tripleDES.CreateDecryptor(rgbKey, s_rgbTripleDES_KW_IV);
byte[] temp2 = dec1.TransformFinalBlock(rgbEncryptedWrappedKeyData, 0, rgbEncryptedWrappedKeyData.Length);
Array.Reverse(temp2);
// Get the IV and temp1
byte[] rgbIV = new byte[8];
Buffer.BlockCopy(temp2, 0, rgbIV, 0, 8);
byte[] temp1 = new byte[temp2.Length - rgbIV.Length];
Buffer.BlockCopy(temp2, 8, temp1, 0, temp1.Length);
ICryptoTransform dec2 = tripleDES.CreateDecryptor(rgbKey, rgbIV);
byte[] rgbWKCKS = dec2.TransformFinalBlock(temp1, 0, temp1.Length);
// checksum the key
byte[] rgbWrappedKeyData = new byte[rgbWKCKS.Length - 8];
Buffer.BlockCopy(rgbWKCKS, 0, rgbWrappedKeyData, 0, rgbWrappedKeyData.Length);
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
byte[] rgbCKS = sha.ComputeHash(rgbWrappedKeyData);
for (int index = rgbWrappedKeyData.Length, index1 = 0; index < rgbWKCKS.Length; index++, index1++)
if (rgbWKCKS[index] != rgbCKS[index1])
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_BadWrappedKeySize"));
return rgbWrappedKeyData;
}
示例2: Decrypt3DES
public static string Decrypt3DES(string CallPassword, string input, string key)
{
if (CallPassword != "ShoveSoft CO.,Ltd -- by Shove 20050709 深圳宝安")
{
return "";
}
TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
provider.Key = Encoding.UTF8.GetBytes(key);
provider.Mode = CipherMode.ECB;
provider.Padding = PaddingMode.Zeros;
ICryptoTransform transform = provider.CreateDecryptor();
byte[] inputBuffer = new byte[input.Length / 2];
for (int i = 0; i < (input.Length / 2); i++)
{
inputBuffer[i] = (byte) Convert.ToInt16(input.Substring(i * 2, 2), 0x10);
}
string str = "";
try
{
str = Encoding.UTF8.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length));
}
catch
{
}
return TrimSlashZero(str);
}
示例3: Decrypt
public static String Decrypt(string encryptedString)
{
string decyprted = null;
byte[] inputBytes = null;
try
{
inputBytes = Convert.FromBase64String(encryptedString);
byte[] pwdhash = null;
MD5CryptoServiceProvider hashmd5;
//generate an MD5 hash from the password.
//a hash is a one way encryption meaning once you generate
//the hash, you cant derive the password back from it.
hashmd5 = new MD5CryptoServiceProvider();
pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
hashmd5 = null;
// Create a new TripleDES service provider
TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
tdesProvider.Key = pwdhash;
tdesProvider.Mode = CipherMode.ECB;
decyprted = ASCIIEncoding.ASCII.GetString(
tdesProvider.CreateDecryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length));
}
catch(Exception e)
{
string str = e.Message;
throw ;
}
return decyprted;
}
示例4: DecryptString
public static string DecryptString(string message)
{
byte[] results;
// Step 1. We hash the customPassPhrase using MD5
// We use the MD5 hash generator as the result is a 128 bit byte array
// which is a valid length for the TripleDES encoder we use below
var hashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = hashProvider.ComputeHash(Encoding.UTF8.GetBytes(customPassPhrase));
// Step 3. Setup the decoder
var tripleDESAlgorithm = new TripleDESCryptoServiceProvider() { Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
tripleDESAlgorithm.Key = TDESKey;
// Step 4. Convert the input string to a byte[]
byte[] dataToDecrypt = Convert.FromBase64String(message);
// Step 5. Attempt to decrypt the string
try
{
ICryptoTransform decryptor = tripleDESAlgorithm.CreateDecryptor();
results = decryptor.TransformFinalBlock(dataToDecrypt, 0, dataToDecrypt.Length);
decryptor.Dispose();
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
tripleDESAlgorithm.Clear();
hashProvider.Clear();
}
// Step 6. Return the decrypted string in UTF8 format
return Encoding.UTF8.GetString(results);
}
示例5: Decrypt
public static string Decrypt(string cypherString, bool useHasing)
{
byte[] keyArray;
byte[] toDecryptArray = Convert.FromBase64String(cypherString);
string key = "uzma";
if (useHasing)
{
MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd.Clear();
}
else
{
keyArray = UTF8Encoding.UTF8.GetBytes(key);
}
TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
tDes.Key = keyArray;
tDes.Mode = CipherMode.ECB;
tDes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tDes.CreateDecryptor();
try
{
byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
tDes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
}
catch (Exception ex)
{
throw ex;
}
}
示例6: Decrypt
/// <summary>
/// Decrypts to provided string parameter.
/// </summary>
public static string Decrypt(string s)
{
if (s == null || s.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Convert.FromBase64String(s);
TripleDESCryptoServiceProvider des =
new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 =
new MD5CryptoServiceProvider();
des.Key =
MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
result = Encoding.ASCII.GetString(
des.CreateDecryptor().TransformFinalBlock(
buffer, 0, buffer.Length));
}
catch
{
throw;
}
return result;
}
示例7: giaiMa
public static string giaiMa(string strGiaiMa)
{
byte[] arrKey;
byte[] arrMahoa = Convert.FromBase64String(strGiaiMa);
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
// Lấy giá trị key từ file Web.config
string keyConfig = (string)settingsReader.GetValue("keyMD5", typeof(String));
MD5CryptoServiceProvider serviceMD5 = new MD5CryptoServiceProvider();
arrKey = serviceMD5.ComputeHash(UTF8Encoding.UTF8.GetBytes(keyConfig));
serviceMD5.Clear(); //Giải phóng tài nguyên
TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
//Thiết lập 1 key cho thuật toán giải mã
tdsp.Key = arrKey;
//Chọn phương thức giải mã. Ở đây chúng ta chọn ECB(Electronic code Book) [1]
tdsp.Mode = CipherMode.ECB;
//Thêm phương thức giải mã IS010126 (random chuỗi kết quả) [2]
tdsp.Padding = PaddingMode.ISO10126;
ICryptoTransform cTransform = tdsp.CreateDecryptor();
byte[] arrKQ = cTransform.TransformFinalBlock(arrMahoa, 0, arrMahoa.Length);
tdsp.Clear(); //Giải phóng tài nguyên của TripleDES Encryptor
// Kết quả giải mã được trả về 1 giá trị kiểu String
return UTF8Encoding.UTF8.GetString(arrKQ);
}
示例8: Decrypt
//Giai ma HashMD5 và TripleDES
public string Decrypt(string cipherString, bool i_blUseHashing)
{
byte[] v_arrKey;
byte[] v_arrEncrypt = new byte[(int)cipherString.Length];
try
{
v_arrEncrypt = Convert.FromBase64String(cipherString);
}
catch (Exception v_ex)
{
throw v_ex;
}
string v_strKey = "fatherofbill";
if (i_blUseHashing)
{
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
v_arrKey = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(v_strKey));
hashmd5.Clear();
}
else
{
v_arrKey = UTF8Encoding.UTF8.GetBytes(v_strKey);
}
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = v_arrKey;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(v_arrEncrypt, 0, v_arrEncrypt.Length);
tdes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray);
}
示例9: Decrypt
public static string Decrypt(string value)
{
byte[] toDecryptArray = Convert.FromBase64String( value );
byte[] keyArray = Convert.FromBase64String( Config.Manager.Framework.Encryption.Key );
byte[] ivArray = Convert.FromBase64String(Config.Manager.Framework.Encryption.IV);
TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
tDes.Key = keyArray;
tDes.Mode = CipherMode.CBC;
tDes.Padding = PaddingMode.PKCS7;
tDes.IV = ivArray;
ICryptoTransform cTransform = tDes.CreateDecryptor();
try
{
byte[] resultArray = cTransform.TransformFinalBlock( toDecryptArray, 0, toDecryptArray.Length );
tDes.Clear();
return UTF8Encoding.UTF8.GetString( resultArray, 0, resultArray.Length );
}
catch( Exception ex )
{
throw ex;
}
}
示例10: CreateDecryptor
public static ICryptoTransform CreateDecryptor(string key, CryptionType type)
{
ICryptoTransform transform;
SHA512 sha512 = new SHA512CryptoServiceProvider();
var bytes = sha512.ComputeHash(Sha1(key).ToAsciiBytes());
switch (type)
{
case CryptionType.Aes:
var aes = Rijndael.Create();
aes.Mode = CipherMode.CBC;
transform = aes.CreateDecryptor(bytes.Skip(17).Take(32).ToArray(), bytes.Skip(17).Take(16).ToArray());
aes.Clear();
break;
case CryptionType.Des:
var des = new DESCryptoServiceProvider { Mode = CipherMode.CBC };
transform = des.CreateDecryptor(bytes.Skip(17).Take(8).ToArray(), bytes.Skip(17).Take(16).ToArray());
des.Clear();
break;
default:
var tripleDes = new TripleDESCryptoServiceProvider { Mode = CipherMode.CBC };
transform = tripleDes.CreateDecryptor(bytes.Skip(17).Take(24).ToArray(), bytes.Skip(17).Take(16).ToArray());
tripleDes.Clear();
break;
}
return transform;
}
示例11: DecryptString
public static string DecryptString(string Message)
{
byte[] Results;
string passphrase = ReadCert();
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
byte[] DataToDecrypt = Convert.FromBase64String(Message);
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
}
finally
{
TDESAlgorithm.Clear();
HashProvider.Clear();
}
return UTF8.GetString(Results);
}
示例12: DecryptString
/// <summary>
/// Decrypts a cipher sting
/// </summary>
/// <param name="cipherString">String to decrypt</param>
/// <returns>Decrypted string</returns>
public string DecryptString(string cipherString)
{
try
{
byte[] keyArray;
byte[] toEncryptArray = Convert.FromBase64String(cipherString);
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
tdes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray);
}
catch (Exception e)
{
Console.WriteLine("DecryptString exception : " + e.ToString());
return null;
}
}
示例13: Decrypt
public static string Decrypt(string cipherString)
{
try
{
byte[] keyArray;
//get the byte code of the string
byte[] toEncryptArray = Convert.FromBase64String(cipherString);
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
hashmd5.Clear();
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(
toEncryptArray, 0, toEncryptArray.Length);
tdes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray);
}
catch (Exception ex)
{
return string.Empty;
}
}
示例14: Decrypt
public string Decrypt(string message)
{
byte[] results;
UTF8Encoding utf8 = new UTF8Encoding();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] deskey = md5.ComputeHash(utf8.GetBytes(Passphrase));
TripleDESCryptoServiceProvider desalg = new TripleDESCryptoServiceProvider();
desalg.Key = deskey;
desalg.Mode = CipherMode.ECB;
desalg.Padding = PaddingMode.PKCS7;
byte[] decryptData = Convert.FromBase64String(message);
try
{
//To transform the utf binary code to md5 decrypt
ICryptoTransform decryptor = desalg.CreateDecryptor();
results = decryptor.TransformFinalBlock(decryptData, 0, decryptData.Length);
}
finally
{
desalg.Clear();
md5.Clear();
}
//TO convert decrypted binery code to string
return utf8.GetString(results);
}
示例15: Decrypt
private const string secureKey = "QaZ1wSx2Edc3RfV4"; //Important Security Key
#endregion Fields
#region Methods
public string Decrypt(string encryptedString)
{
try
{
byte[] extractBytes = Convert.FromBase64String(encryptedString); //getting the string to decrypt
MD5CryptoServiceProvider descObj = new MD5CryptoServiceProvider(); //creating an instance of MD5CryptoServiceProvider
byte[] hashCompute = descObj.ComputeHash(UTF8Encoding.UTF8.GetBytes(secureKey));
descObj.Clear(); //releasing resourse
TripleDESCryptoServiceProvider DESCD = new TripleDESCryptoServiceProvider();
DESCD.Key = hashCompute; //secure Key is being set
DESCD.Mode = CipherMode.ECB; //Electronic Code Book Mode
DESCD.Padding = PaddingMode.PKCS7; //Padding
ICryptoTransform ICTransform = DESCD.CreateDecryptor();
byte[] finalResult = ICTransform.TransformFinalBlock( //Transforming byte array to finalResult
extractBytes, 0, extractBytes.Length);
DESCD.Clear();
return UTF8Encoding.UTF8.GetString(finalResult); //Return Decrypted Text
}
catch (Exception ex)
{
return ex.ToString();
}
}