本文整理汇总了C#中RijndaelManaged类的典型用法代码示例。如果您正苦于以下问题:C# RijndaelManaged类的具体用法?C# RijndaelManaged怎么用?C# RijndaelManaged使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RijndaelManaged类属于命名空间,在下文中一共展示了RijndaelManaged类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Decrypt
/// <summary>
/// Decrypts a Base64 encoded string previously generated with a specific crypt class, returns a string
/// </summary>
/// <param name="cipherText">A base64 encoded string containing encryption information</param>
/// <param name="passPhrase">The passphrase used to encrypt the inputed text</param>
/// <returns></returns>
public string Decrypt(string cipherText, string passPhrase)
{
try
{
var ciphertextS = DecodeFrom64(cipherText);
var ciphersplit = Regex.Split(ciphertextS, "-");
var passsalt = Convert.FromBase64String(ciphersplit[1]);
var initVectorBytes = Convert.FromBase64String(ciphersplit[0]);
var cipherTextBytes = Convert.FromBase64String(ciphersplit[2]);
var password = new PasswordDeriveBytes(passPhrase, passsalt, "SHA512", 100);
var keyBytes = password.GetBytes(256/8);
var symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
var decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
var memoryStream = new MemoryStream(cipherTextBytes);
var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
var plainTextBytes = new byte[cipherTextBytes.Length];
var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
}
catch (Exception m)
{
return "error";
}
}
开发者ID:BinaryEvolved,项目名称:C-AES256-Encryption-Class,代码行数:33,代码来源:Crypt.cs
示例2: DecryptRijndael
public static string DecryptRijndael(string encryptedString)
{
byte[] encrypted;
byte[] fromEncrypted;
UTF8Encoding utf8Converter = new UTF8Encoding();
encrypted = Convert.FromBase64String(encryptedString);
RijndaelManaged myRijndael = new RijndaelManaged();
ICryptoTransform decryptor = myRijndael.CreateDecryptor(Key, IV);
MemoryStream ms = new MemoryStream(encrypted);
CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
fromEncrypted = new byte[encrypted.Length];
cs.Read(fromEncrypted, 0, fromEncrypted.Length);
string decryptedString = utf8Converter.GetString(fromEncrypted);
int indexNull = decryptedString.IndexOf("\0");
if (indexNull > 0)
{
decryptedString = decryptedString.Substring(0, indexNull);
}
return decryptedString;
}
开发者ID:ivladyka,项目名称:OurTravels,代码行数:30,代码来源:Encrypt.cs
示例3: Encrypt
public static byte[] Encrypt(byte[] data, string password)
{
byte[] result = null;
byte[] passwordBytes = Encoding.Default.GetBytes(password);
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
AES.KeySize = keySize;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes, salt, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(data, 0, data.Length);
cs.Close();
}
result = ms.ToArray();
}
}
return result;
}
开发者ID:Syriamanal,项目名称:xprotect,代码行数:26,代码来源:Encryption.cs
示例4: Encrypt
// Token: 0x06000EF7 RID: 3831 RVA: 0x00045348 File Offset: 0x00043548
public static string Encrypt(string unencrypted)
{
RijndaelManaged rijndaelManaged = new RijndaelManaged();
ICryptoTransform encryptor = rijndaelManaged.CreateEncryptor(SimpleAES.key, SimpleAES.vector);
UTF8Encoding uTF8Encoding = new UTF8Encoding();
return Convert.ToBase64String(SimpleAES.Encrypt(uTF8Encoding.GetBytes(unencrypted), encryptor));
}
开发者ID:interrupt21h,项目名称:twodots_decrypt,代码行数:8,代码来源:SimpleAES_encrypt.cs
示例5: Decrypt
// Token: 0x06000EF8 RID: 3832 RVA: 0x00045384 File Offset: 0x00043584
public static string Decrypt(string encrypted)
{
RijndaelManaged rijndaelManaged = new RijndaelManaged();
ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(SimpleAES.key, SimpleAES.vector);
UTF8Encoding uTF8Encoding = new UTF8Encoding();
return uTF8Encoding.GetString(SimpleAES.Decrypt(Convert.FromBase64String(encrypted), decryptor));
}
开发者ID:interrupt21h,项目名称:twodots_decrypt,代码行数:8,代码来源:SimpleAES_encrypt.cs
示例6: EncryptFile
public static void EncryptFile(string path)
{
if (!File.Exists(path))
{
Debug.Log("File Not Found At: " + path);
return;
}
XmlDocument xmlFile = new XmlDocument();
xmlFile.Load(path);
XmlElement xmlRoot = xmlFile.DocumentElement;
if (xmlRoot.ChildNodes.Count > 1)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("86759426197648123460789546213421");
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (xmlRoot.InnerXml);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
xmlRoot.InnerXml = Convert.ToBase64String (resultArray, 0, resultArray.Length);
}
xmlFile.Save(path);
}
开发者ID:jcabe4,项目名称:Reignite,代码行数:27,代码来源:XMLFileManager.cs
示例7: Decrypt
/// <summary>
/// Decrypts a previously encrypted string.
/// </summary>
/// <param name="inputText">The encrypted string to decrypt.</param>
/// <returns>A decrypted string.</returns>
public static string Decrypt(string inputText)
{
string decrypted = null;
try
{
RijndaelManaged rijndaelCipher = new RijndaelManaged();
byte[] encryptedData = Convert.FromBase64String(inputText);
PasswordDeriveBytes secretKey = new PasswordDeriveBytes(ENCRYPTION_KEY, SALT);
using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (MemoryStream memoryStream = new MemoryStream(encryptedData))
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
byte[] plainText = new byte[encryptedData.Length];
int decryptedCount = cryptoStream.Read(plainText, 0, plainText.Length);
decrypted = Encoding.Unicode.GetString(plainText, 0, decryptedCount);
}
}
}
}
catch (Exception)
{
}
return decrypted;
}
开发者ID:kiquenet,项目名称:B4F,代码行数:32,代码来源:QueryStringModule.cs
示例8: GenerateEncryptionVector
/// Generates a unique encryption vector
public static byte[] GenerateEncryptionVector()
{
//Generate a Vector
RijndaelManaged rm = new RijndaelManaged();
rm.GenerateIV();
return rm.IV;
}
开发者ID:skuffe,项目名称:MailClient,代码行数:8,代码来源:SimpleAES.cs
示例9: DecryptFile
internal static bool DecryptFile(string inputPath, string outputPath, string password)
{
var input = new FileStream(inputPath, FileMode.Open, FileAccess.Read);
var output = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write);
// Essentially, if you want to use RijndaelManaged as AES you need to make sure that:
// 1.The block size is set to 128 bits
// 2.You are not using CFB mode, or if you are the feedback size is also 128 bits
RijndaelManaged algorithm = new RijndaelManaged {KeySize = 256, BlockSize = 128};
algorithm.Mode = CipherMode.CBC;
var key = new Rfc2898DeriveBytes(password, Encoding.ASCII.GetBytes(Salt));
algorithm.Key = key.GetBytes(algorithm.KeySize/8);
algorithm.IV = key.GetBytes(algorithm.BlockSize/8);
try
{
using (var decryptedStream = new CryptoStream(output, algorithm.CreateDecryptor(), CryptoStreamMode.Write))
{
CopyStream(input, decryptedStream);
return true;
}
}
catch (CryptographicException)
{
throw new InvalidDataException("Please supply a correct password");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
开发者ID:Whitetigerswt,项目名称:SAMP_AC_Extension,代码行数:34,代码来源:AES.cs
示例10: AES_Encrypt
public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
{
byte[] encryptedBytes = null;
// Set your salt here, change it to meet your flavor:
// The salt bytes must be at least 8 bytes.
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
AES.KeySize = 256;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
return encryptedBytes;
//end public byte[] AES_Encrypt
}
开发者ID:JorgMU,项目名称:AES256,代码行数:33,代码来源:SimpleAES256.cs
示例11: DecryptFile
//Decrypts the save file for loading purposes
public static void DecryptFile(string path)
{
if(!File.Exists(path))
{
Debug.Log("File Not Found At: " + path);
return;
}
XDocument xmlFile = XDocument.Load (path);
XmlReader reader = xmlFile.CreateReader ();
reader.MoveToContent ();
if(xmlFile.Root.Elements() != null)
{
Debug.Log("decrypting");
byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("86759426197648123460789546213421");
byte[] toEncryptArray = Convert.FromBase64String (reader.ReadInnerXml());
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
string data = (UTF8Encoding.UTF8.GetString (resultArray));
data = "<Root>" + data + "</Root>";
xmlFile = (XDocument.Parse(data));
}
xmlFile.Save(path);
}
开发者ID:Jetblacktsunami,项目名称:CSE455-Salvage,代码行数:32,代码来源:XMLFileManager.cs
示例12: EncryptFile
//Encrypts the save file to prevent modification
public static void EncryptFile(string path)
{
if(!File.Exists(path))
{
Debug.Log("File Not Found At: " + path);
return;
}
XDocument xmlFile = XDocument.Load(path);
XmlReader reader = xmlFile.CreateReader();
reader.MoveToContent();
if(xmlFile.Root.HasElements)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("86759426197648123460789546213421");
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (reader.ReadInnerXml());
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
xmlFile.Root.ReplaceNodes(Convert.ToBase64String (resultArray, 0, resultArray.Length));
}
xmlFile.Save(path);
}
开发者ID:Jetblacktsunami,项目名称:CSE455-Salvage,代码行数:27,代码来源:XMLFileManager.cs
示例13: AES_Decrypt
private static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
{
byte[] decryptedBytes = null;
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
try
{
AES.KeySize = AESKeySize_256;
AES.Key = passwordBytes;
AES.Mode = AESCipherMode_ECB;
AES.Padding = AESPadding_PKCS7;
using (CryptoStream cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
cs.Close();
}
decryptedBytes = ms.ToArray();
}
catch (CryptographicException e)
{
throw e;
}
}
}
return decryptedBytes;
}
开发者ID:neiltuma,项目名称:steve_prj,代码行数:31,代码来源:testSSO.aspx.cs
示例14: DecryptStream
/// <summary>
/// Decrypt byte array
/// </summary>
/// <param name="dataStream">encrypted data array</param>
/// <param name="password">password</param>
/// <returns>unencrypted data array</returns>
private static byte[] DecryptStream(byte[] dataStream, string password)
{
SqlPipe pipe = SqlContext.Pipe;
//the decrypter
RijndaelManaged cryptic = new RijndaelManaged
{
Key = Encoding.ASCII.GetBytes(password),
IV = Encoding.ASCII.GetBytes("1qazxsw23edcvfr4"),
Padding = PaddingMode.ISO10126,
};
//Get a decryptor that uses the same key and IV as the encryptor used.
ICryptoTransform decryptor = cryptic.CreateDecryptor();
//Now decrypt encrypted data stream
MemoryStream msDecrypt = new MemoryStream(dataStream);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
byte[] fromEncrypt = new byte[dataStream.Length];
//Read the data out of the crypto stream.
try
{
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
}
catch (Exception e)
{
pipe.Send("Failed to decrypt data");
pipe.Send(e.Message);
throw;
}
return fromEncrypt;
}
开发者ID:SQLServerIO,项目名称:SQL-Server-File-System-Tools,代码行数:40,代码来源:FileSystemHelpers.cs
示例15: Encrypt
public static byte[] Encrypt(byte[] PlainBytes, byte[] Key,byte[] IV )
{
byte[] encrypted;
// Create an RijndaelManaged object
// with the specified key and IV.
using (RijndaelManaged rijAlg = new RijndaelManaged())
{
rijAlg.Key = Key;
rijAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
// Create the streams used for encryption.
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
csEncrypt.Write(PlainBytes,0,PlainBytes.Length);
csEncrypt.FlushFinalBlock();
encrypted = msEncrypt.ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}
开发者ID:FlameskyDexive,项目名称:hugula,代码行数:28,代码来源:CryptographHelper.cs
示例16: AES
public AES()
{
RijndaelManaged rm = new RijndaelManaged();
_encryptor = rm.CreateEncryptor(_key, _vector);
_decryptor = rm.CreateDecryptor(_key, _vector);
encoder = new UTF8Encoding();
}
开发者ID:SteinLabs,项目名称:Gravity,代码行数:7,代码来源:AES.cs
示例17: Encrypt
/// <summary>
/// Encrypt string using AES 128
/// </summary>
/// <param name="plaintext"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Encrypt(string plaintext, string key)
{
byte[] keybytes = Encoding.UTF8.GetBytes(key);
RijndaelManaged aes = new RijndaelManaged();
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
byte[] IVbytes = Encoding.ASCII.GetBytes("dongbinhuiasxiny");
ICryptoTransform encryptor = aes.CreateEncryptor(keybytes, IVbytes);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
byte[] plainBytes = Encoding.UTF8.GetBytes(Convert.ToBase64String(Encoding.UTF8.GetBytes(plaintext)));
cs.Write(plainBytes, 0, plainBytes.Length);
cs.FlushFinalBlock();
byte[] cipherBytes = ms.ToArray();
ms.Close();
cs.Close();
return Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
}
开发者ID:masterjay,项目名称:BankofTaiwanActive,代码行数:32,代码来源:libAES.cs
示例18: DecryptString
protected string DecryptString(string InputText, string Password)
{
try
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
byte[] EncryptedData = Convert.FromBase64String(InputText);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
// Create a decryptor from the existing SecretKey bytes.
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(16), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream(EncryptedData);
// Create a CryptoStream. (always use Read mode for decryption).
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
// Since at this point we don't know what the size of decrypted data
// will be, allocate the buffer long enough to hold EncryptedData;
// DecryptedData is never longer than EncryptedData.
byte[] PlainText = new byte[EncryptedData.Length];
// Start decrypting.
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
memoryStream.Close();
cryptoStream.Close();
// Convert decrypted data into a string.
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
// Return decrypted string.
return DecryptedData;
}
catch (Exception exception)
{
return (exception.Message);
}
}
开发者ID:DawnShift,项目名称:Multi-cloud-Encryption-,代码行数:31,代码来源:Cryptography.cs
示例19: GenerateEncryptionKey
/// -------------- Two Utility Methods (not used but may be useful) -----------
/// Generates an encryption key.
public static byte[] GenerateEncryptionKey()
{
//Generate a Key.
RijndaelManaged rm = new RijndaelManaged();
rm.GenerateKey();
return rm.Key;
}
开发者ID:skuffe,项目名称:MailClient,代码行数:9,代码来源:SimpleAES.cs
示例20: Encrypt
public static string Encrypt(string plainText, string passPhrase)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
{
byte[] keyBytes = password.GetBytes(keysize / 8);
using (RijndaelManaged symmetricKey = new RijndaelManaged())
{
symmetricKey.Mode = CipherMode.CBC;
using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
return Convert.ToBase64String(cipherTextBytes);
}
}
}
}
}
}
开发者ID:LCruel,项目名称:LCrypt2,代码行数:25,代码来源:Program.cs
注:本文中的RijndaelManaged类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论