本文整理汇总了C#中RijndaelManaged.CreateEncryptor方法的典型用法代码示例。如果您正苦于以下问题:C# RijndaelManaged.CreateEncryptor方法的具体用法?C# RijndaelManaged.CreateEncryptor怎么用?C# RijndaelManaged.CreateEncryptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RijndaelManaged
的用法示例。
在下文中一共展示了RijndaelManaged.CreateEncryptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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));
}
示例4: AES
public AES()
{
RijndaelManaged rm = new RijndaelManaged();
_encryptor = rm.CreateEncryptor(_key, _vector);
_decryptor = rm.CreateDecryptor(_key, _vector);
encoder = new UTF8Encoding();
}
示例5: 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;
}
示例6: 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);
}
示例7: 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);
}
}
}
}
}
}
示例8: 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);
}
示例9: 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
}
示例10: SimpleAES
public SimpleAES()
{
//This is our encryption method
RijndaelManaged rm = new RijndaelManaged();
//Create an encryptor and a decryptor using our encryption method, key, and vector.
EncryptorTransform = rm.CreateEncryptor(this.Key, this.Vector);
DecryptorTransform = rm.CreateDecryptor(this.Key, this.Vector);
//Used to translate bytes to text and vice versa
UTFEncoder = new System.Text.UTF8Encoding();
}
示例11: CsharpCryptography
/// <summary>
/// Constructor
///
/// <param name="password">Public key
public CsharpCryptography(string password)
{
//Encode digest
var md5 = new MD5CryptoServiceProvider();
_password = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
//Initialize objects
_cipher = new RijndaelManaged();
_cipher.Padding = PaddingMode.PKCS7;
_decryptor = _cipher.CreateDecryptor(_password, IV);
_encryptor = _cipher.CreateEncryptor(_password, IV);
}
示例12: Test
static Boolean Test(CipherMode md)
{
Byte[] PlainText = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
Byte[] Key = {1, 1, 1, 1, 1, 1, 1, 1,2,2,2,2,2,2,2,2};
Byte[] IV = {100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115};
Console.WriteLine("Encrypting the following bytes:");
PrintByteArray(PlainText);
RijndaelManaged des = new RijndaelManaged();
des.Mode = md;
// des.FeedbackSize = 0;
// des.Padding = PaddingMode.PKCS7;
Console.WriteLine("DES default key size = " + des.KeySize);
ICryptoTransform sse = des.CreateEncryptor(Key, IV);
Console.WriteLine("SSE mode = " + des.Mode);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, sse, CryptoStreamMode.Write);
cs.Write(PlainText,0,PlainText.Length);
cs.FlushFinalBlock();
byte[] CipherText = ms.ToArray();
cs.Close();
Console.WriteLine("Cyphertext:");
PrintByteArray(CipherText);
Console.WriteLine("Decrypting...");
// RijndaelManaged des = new RijndaelManaged();
// des.Mode = CipherMode.ECB;
// des.FeedbackSize = 0;
ICryptoTransform ssd = des.CreateDecryptor(Key, IV);
Console.WriteLine("SSD mode = " + des.Mode);
cs = new CryptoStream(new MemoryStream(CipherText), ssd, CryptoStreamMode.Read);
byte[] NewPlainText = new byte[PlainText.Length];
cs.Read(NewPlainText,0,PlainText.Length);
PrintByteArray(NewPlainText);
if (!Compare(PlainText, NewPlainText)) {
Console.WriteLine("ERROR: roundtrip failed");
return false;
}
return true;
}
示例13: Encrypt
public string Encrypt(string toE)
{
//加密和解密采用相同的key,具体自己填,但是必须为32位//
byte[] keyArray = UTF8Encoding.UTF8.GetBytes(KEY);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toE);
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray,0,toEncryptArray.Length);
return Convert.ToBase64String(resultArray,0,resultArray.Length);
}
示例14: DeleteFile
public void DeleteFile()
{
string output_file = "characters.xml";
string character_directory = "Saved Data";
List<string> keyList = new List<string>();
List<string> contentList = new List<string>();
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] key = null;
RijndaelManaged RMCrypto = new RijndaelManaged();
string currentPath = Directory.GetCurrentDirectory();
Data_Loader Load = ScriptableObject.CreateInstance<Data_Loader>();
Data_Saver Save = ScriptableObject.CreateInstance<Data_Saver>();
List<string> tempList = new List<string>();
contentList = Save.GetAllData();
character_directory = Path.Combine(currentPath, character_directory);
output_file = Path.Combine(character_directory, output_file);
//Get key in byte form
XML_Loader XML = ScriptableObject.CreateInstance<XML_Loader>();
key = encoding.GetBytes(Data_Handler_Key.keyvalue);
//Collect data to be saved and write it to an encrypted xml file using the key retrieved earlier
FileStream encrypted_file = new FileStream(output_file, FileMode.Create);
CryptoStream cryptography_stream = new CryptoStream(encrypted_file, RMCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (StreamWriter swEncrypt = new StreamWriter(cryptography_stream))
{
swEncrypt.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
swEncrypt.WriteLine("<savedcharacters>");
foreach (var content in contentList)
{
swEncrypt.WriteLine(content);
}
contentList.Clear();
swEncrypt.WriteLine("</savedcharacters>");
}
}
cryptography_stream.Close();
encrypted_file.Close();
tempList = Load.LoadCharacterIDs();
}
示例15: Encripta
public static string Encripta(string Cadena)
{
byte[] inputBytes = Encoding.ASCII.GetBytes(Cadena);
byte[] encripted;
RijndaelManaged cripto = new RijndaelManaged();
using (MemoryStream ms = new MemoryStream(inputBytes.Length))
{
using (CryptoStream objCryptoStream = new CryptoStream(ms, cripto.CreateEncryptor(Clave, IV), CryptoStreamMode.Write))
{
objCryptoStream.Write(inputBytes, 0, inputBytes.Length);
objCryptoStream.FlushFinalBlock();
objCryptoStream.Close();
}
encripted = ms.ToArray();
}
return Convert.ToBase64String(encripted);
}