本文整理汇总了C#中System.Security.Cryptography.Aes类的典型用法代码示例。如果您正苦于以下问题:C# Aes类的具体用法?C# Aes怎么用?C# Aes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Aes类属于System.Security.Cryptography命名空间,在下文中一共展示了Aes类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:AESKnownEnc2.cs
示例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);
}
});
}
}
开发者ID:nelsonst47,项目名称:keepasshttp,代码行数:29,代码来源:Handlers.cs
示例3: RijndaelImplementation
internal RijndaelImplementation()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
// This class wraps Aes
_impl = Aes.Create();
}
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:RijndaelImplementation.cs
示例4: RijndaelManaged
public RijndaelManaged()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
// This class wraps Aes
_impl = Aes.Create();
}
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:RijndaelManaged.cs
示例5: Client
internal Client(TcpClient c, string u, Aes a)
{
this.c = c;
this.u = u;
this.a = a;
s = c.GetStream();
}
开发者ID:Connorcpu,项目名称:Connorchat,代码行数:7,代码来源:Client.cs
示例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);
}
}
开发者ID:SqueeG,项目名称:keepasshttp,代码行数:32,代码来源:Handlers.cs
示例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);
}
开发者ID:iwikimon,项目名称:diplom,代码行数:7,代码来源:AESCrypto.cs
示例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);
}
开发者ID:JamesHagerman,项目名称:sftprelay,代码行数:31,代码来源:AESCBC.cs
示例9: AesCrypt
public AesCrypt()
{
aes = Aes.Create();
aes.Mode = CipherMode.CBC;
aes.GenerateIV();
aes.GenerateKey();
aes.Padding = PaddingMode.PKCS7;
}
开发者ID:eoftedal,项目名称:PoetAndDidntKnowIt,代码行数:8,代码来源:AesCrypt.cs
示例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;
}
开发者ID:Aldjinn,项目名称:keepasshttp,代码行数:58,代码来源:Handlers.cs
示例11: MapleAESOFB
static MapleAESOFB()
{
AES = Aes.Create();
AES.KeySize = 256;
AES.BlockSize = 128;
AES.Mode = CipherMode.CBC;
Zeroes = new byte[((BlockLength >> 4) + 1) << 4];
}
开发者ID:Meiodine,项目名称:Meiodine,代码行数:9,代码来源:MapleAESOFB.cs
示例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();
}
开发者ID:vprovalov,项目名称:passie,代码行数:9,代码来源:KeePassConnection.cs
示例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);
}
开发者ID:rockyx,项目名称:dntdiag,代码行数:10,代码来源:DBCrypto.cs
示例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;
}
开发者ID:Arcidev,项目名称:Arci.Networking,代码行数:15,代码来源:AesEncryptor.cs
示例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);
}
开发者ID:jafnharr,项目名称:cryptkeeper,代码行数:10,代码来源:SimpleAes.cs
示例16: VerifyRequest
private bool VerifyRequest(Request r, Aes aes)
{
var entry = GetConfigEntry(false);
if (entry == null)
return false;
var s = entry.Strings.Get(ASSOCIATE_KEY_PREFIX + r.Id);
if (s == null)
return false;
return TestRequestVerifier(r, aes, s.ReadString());
}
开发者ID:jaketyler,项目名称:keepasshttp,代码行数:11,代码来源:Protocol.cs
示例17: Decrypt
public void Decrypt(String inputFile, String outputFile, Aes aes)
{
if (!IsEncrypted (inputFile)) {
return;
}
this.Logger.LogDebug (String.Format (CultureInfo.CurrentCulture, "Decrypting {0}...", inputFile));
byte[] data = File.ReadAllBytes (inputFile);
byte[] output = Decrypt (data, aes);
File.WriteAllBytes (outputFile, output);
}
开发者ID:Monobjc,项目名称:monobjc-tools,代码行数:12,代码来源:FileEncrypter.cs
示例18: AesCtrCryptoTransform
/// <summary>ctor</summary>
public AesCtrCryptoTransform(byte[] key, ArraySegment<byte> counterBufferSegment, Func<Aes> aesFactory = null)
{
if (counterBufferSegment.Count != AesConstants.AES_BLOCK_SIZE)
throw new ArgumentException("counterBufferSegment.Count must be " + AesConstants.STR_AES_BLOCK_SIZE + ".");
this.aes = aesFactory == null ? AesFactories.Aes() : aesFactory();
this.aes.Mode = CipherMode.ECB;
this.aes.Padding = PaddingMode.None;
Utils.BlockCopy(counterBufferSegment.Array, counterBufferSegment.Offset, counterBuffer, 0, AesConstants.AES_BLOCK_SIZE);
this.cryptoTransform = aes.CreateEncryptor(rgbKey: key, rgbIV: null);
}// ctor
开发者ID:thegeekinside,项目名称:SecurityDriven.Inferno,代码行数:13,代码来源:AesCtrCryptoTransform.cs
示例19: AesCtrCryptoTransform
/// <summary>
/// ctor
/// </summary>
/// <param name="key"></param>
/// <param name="counterBufferSegment"></param>
/// <param name="aesFactory"></param>
/// <exception cref="ArgumentException">
/// <paramref name="counterBufferSegment"/> needs to have the same length as <see cref="AesConstants.STR_AES_BLOCK_SIZE"/>.
/// </exception>
public AesCtrCryptoTransform(byte[] key, ArraySegment<byte> counterBufferSegment, Func<Aes> aesFactory = null)
{
if (counterBufferSegment.Count != AesConstants.AES_BLOCK_SIZE)
throw new ArgumentException($"{nameof(counterBufferSegment)}.Count must be {AesConstants.STR_AES_BLOCK_SIZE}.", nameof(counterBufferSegment));
_aes = aesFactory?.Invoke() ?? CipherFactory.Aes();
_aes.Mode = CipherMode.ECB;
_aes.Padding = PaddingMode.None;
Buffer.BlockCopy(counterBufferSegment.Array, counterBufferSegment.Offset, _counterBuffer.Value, 0, AesConstants.AES_BLOCK_SIZE);
_cryptoTransform = _aes.CreateEncryptor(rgbKey: key, rgbIV: null);
}
开发者ID:YoloDev,项目名称:YoloDev.Skiba,代码行数:21,代码来源:AesCtrCryptoTransform.cs
示例20: init
public override void init(int mode, byte[] key, byte[] iv)
{
for (int i = 0; i < counter.Length; i++)
counter[i] = 0;
for (int i = 0; i < counterBytes.Length; i++)
counterBytes[i] = 0;
aesm = AesManaged.Create();
aesm.BlockSize = blockSize*8;
//aesm.KeySize = blockSize*8;
aesm.Key = key;
aesm.IV = iv;
ms = new MemoryStream(blockSize);
}
开发者ID:JamesHagerman,项目名称:sftprelay,代码行数:13,代码来源:AESCTR.cs
注:本文中的System.Security.Cryptography.Aes类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论