本文整理汇总了C#中System.Security.Cryptography.Aes类的典型用法代码示例。如果您正苦于以下问题:C# Aes类的具体用法?C# Aes怎么用?C# Aes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Aes类属于System.Security.Cryptography命名空间,在下文中一共展示了Aes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestKnownEnc
static Boolean TestKnownEnc(Aes aes, Byte[] Key, Byte[] IV, Byte[] Plain, Byte[] Cipher)
{
Byte[] CipherCalculated;
Console.WriteLine("Encrypting the following bytes:");
PrintByteArray(Plain);
Console.WriteLine("With the following Key:");
PrintByteArray(Key);
Console.WriteLine("and IV:");
PrintByteArray(IV);
Console.WriteLine("Expecting this ciphertext:");
PrintByteArray(Cipher);
ICryptoTransform sse = aes.CreateEncryptor(Key, IV);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, sse, CryptoStreamMode.Write);
cs.Write(Plain,0,Plain.Length);
cs.FlushFinalBlock();
CipherCalculated = ms.ToArray();
cs.Close();
Console.WriteLine("Computed this cyphertext:");
PrintByteArray(CipherCalculated);
if (!Compare(Cipher, CipherCalculated)) {
Console.WriteLine("ERROR: result is different from the expected");
return false;
}
Console.WriteLine("OK");
return true;
}
示例2: AssociateHandler
private void AssociateHandler(Request r, Response resp, Aes aes)
{
if (!TestRequestVerifier(r, aes, r.Key))
return;
// key is good, prompt user to save
using (var f = new ConfirmAssociationForm())
{
var win = host.MainWindow;
win.Invoke((MethodInvoker)delegate
{
ShowNotification("New key association requested", (s, e) => f.Activate());
f.Icon = win.Icon;
f.Key = r.Key;
f.Load += delegate { f.Activate(); };
f.ShowDialog(win);
if (f.KeyId != null)
{
var entry = GetConfigEntry(true);
entry.Strings.Set(ASSOCIATE_KEY_PREFIX + f.KeyId, new ProtectedString(true, r.Key));
entry.Touch(true);
resp.Id = f.KeyId;
resp.Success = true;
SetResponseVerifier(resp, aes);
UpdateUI(null);
}
});
}
}
示例3: RijndaelImplementation
internal RijndaelImplementation()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
// This class wraps Aes
_impl = Aes.Create();
}
示例4: RijndaelManaged
public RijndaelManaged()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
// This class wraps Aes
_impl = Aes.Create();
}
示例5: Client
internal Client(TcpClient c, string u, Aes a)
{
this.c = c;
this.u = u;
this.a = a;
s = c.GetStream();
}
示例6: GetAllLoginsHandler
private void GetAllLoginsHandler(Request r, Response resp, Aes aes)
{
if (!VerifyRequest(r, aes))
return;
var list = new PwObjectList<PwEntry>();
var root = host.Database.RootGroup;
var parms = MakeSearchParameters();
parms.SearchString = @"^[A-Za-z0-9:/-]+\.[A-Za-z0-9:/-]+$"; // match anything looking like a domain or url
root.SearchEntries(parms, list);
foreach (var entry in list)
{
var name = entry.Strings.ReadSafe(PwDefs.TitleField);
var login = GetUserPass(entry)[0];
var uuid = entry.Uuid.ToHexString();
var e = new ResponseEntry(name, login, null, uuid, null);
resp.Entries.Add(e);
}
resp.Success = true;
resp.Id = r.Id;
SetResponseVerifier(resp, aes);
foreach (var entry in resp.Entries)
{
entry.Name = CryptoTransform(entry.Name, false, true, aes, CMode.ENCRYPT);
entry.Login = CryptoTransform(entry.Login, false, true, aes, CMode.ENCRYPT);
entry.Uuid = CryptoTransform(entry.Uuid, false, true, aes, CMode.ENCRYPT);
}
}
示例7: AESCrypto
private AESCrypto()
{
var pdb = new Rfc2898DeriveBytes(aesPasswd, aesSalt);
aes = new AesManaged();
aes.Key = pdb.GetBytes(aes.KeySize / 8);
aes.IV = pdb.GetBytes(aes.BlockSize / 8);
}
示例8: init
public override void init(int mode, byte[] key, byte[] iv)
{
if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE) throw new ArgumentOutOfRangeException();
ms = new PipedMemoryStream();
aesm = AesManaged.Create();
aesm.BlockSize = blockSize * 8;
aesm.Padding = PaddingMode.None;
ICryptoTransform ict;
if (key.Length > blockSize)
{
byte[] tmp = new byte[blockSize];
Array.Copy(key, 0, tmp, 0, tmp.Length);
key = tmp;
}
if (iv.Length > ivSize)
{
byte[] tmp = new byte[ivSize];
Array.Copy(iv, 0, tmp, 0, tmp.Length);
iv = tmp;
}
if (mode == ENCRYPT_MODE)
{
ict = aesm.CreateEncryptor(key, iv);
}
else
{
ict = aesm.CreateDecryptor(key, iv);
}
cs = new CryptoStream(ms, ict, CryptoStreamMode.Write);
}
示例9: AesCrypt
public AesCrypt()
{
aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.GenerateIV();
aes.GenerateKey();
aes.Padding = PaddingMode.PKCS7;
}
示例10: FindMatchingEntries
private IEnumerable<PwEntry> FindMatchingEntries(Request r, Aes aes)
{
string submithost = null;
string realm = null;
var list = new PwObjectList<PwEntry>();
string formhost, searchHost;
formhost = searchHost = GetHost(CryptoTransform(r.Url, true, false, aes, CMode.DECRYPT));
if (r.SubmitUrl != null) {
submithost = GetHost(CryptoTransform(r.SubmitUrl, true, false, aes, CMode.DECRYPT));
}
if (r.Realm != null)
realm = CryptoTransform(r.Realm, true, false, aes, CMode.DECRYPT);
var origSearchHost = searchHost;
var parms = MakeSearchParameters();
var root = host.Database.RootGroup;
while (list.UCount == 0 && (origSearchHost == searchHost || searchHost.IndexOf(".") != -1))
{
parms.SearchString = String.Format("^{0}$|/{0}/?", searchHost);
root.SearchEntries(parms, list);
searchHost = searchHost.Substring(searchHost.IndexOf(".") + 1);
if (searchHost == origSearchHost)
break;
}
Func<PwEntry, bool> filter = delegate(PwEntry e)
{
var title = e.Strings.ReadSafe(PwDefs.TitleField);
var entryUrl = e.Strings.ReadSafe(PwDefs.UrlField);
var c = GetEntryConfig(e);
if (c != null)
{
if (c.Allow.Contains(formhost) && (submithost == null || c.Allow.Contains(submithost)))
return true;
if (c.Deny.Contains(formhost) || (submithost != null && c.Deny.Contains(submithost)))
return false;
if (realm != null && c.Realm != realm)
return false;
}
if (title.StartsWith("http://") || title.StartsWith("https://"))
{
var u = new Uri(title);
if (formhost.Contains(u.Host))
return true;
}
if (entryUrl != null && entryUrl.StartsWith("http://") || entryUrl.StartsWith("https://"))
{
var u = new Uri(entryUrl);
if (formhost.Contains(u.Host))
return true;
}
return formhost.Contains(title) || (entryUrl != null && formhost.Contains(entryUrl));
};
return from e in list where filter(e) select e;
}
示例11: MapleAESOFB
static MapleAESOFB()
{
AES = Aes.Create();
AES.KeySize = 256;
AES.BlockSize = 128;
AES.Mode = CipherMode.CBC;
Zeroes = new byte[((BlockLength >> 4) + 1) << 4];
}
示例12: KeePassConnection
public KeePassConnection(string host, int port, string id, byte[] key)
{
this.Host = host;
this.Port = port;
this.Hash = null;
this.Id = id;
this.Key = key;
this.aes = key != null ? new AesManaged {Key = key} : new AesManaged();
}
示例13: DBCrypto
static DBCrypto()
{
aesAlg = Aes.Create();
aesAlg.Key = AES_CBC_KEY;
aesAlg.IV = AES_CBC_IV;
aesAlg.Padding = PaddingMode.PKCS7;
decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
}
示例14: AesEncryptor
/// <summary>
/// Creates AES instance
/// </summary>
/// <param name="key">Key to be set as AES key</param>
/// <param name="iVec">IVec to be set as AES iVec</param>
public AesEncryptor(byte[] key, byte[] iVec)
{
this.key = key;
this.iVec = iVec;
aes = Aes.Create();
aes.IV = iVec;
aes.Key = key;
aes.Padding = PaddingMode.Zeros;
}
示例15: SimpleAes
public SimpleAes(byte[] key)
{
aes = Aes.Create();
aes.GenerateIV();
aes.Key = key;
encryptor = aes.CreateEncryptor(key, aes.IV);
decryptor = aes.CreateDecryptor(key, aes.IV);
}