本文整理汇总了C#中ICryptoTransform类的典型用法代码示例。如果您正苦于以下问题:C# ICryptoTransform类的具体用法?C# ICryptoTransform怎么用?C# ICryptoTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICryptoTransform类属于命名空间,在下文中一共展示了ICryptoTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CryptoStream
public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
{
if ((mode == CryptoStreamMode.Read) && (!stream.CanRead)) {
throw new ArgumentException (
Locale.GetText ("Can't read on stream"));
}
if ((mode == CryptoStreamMode.Write) && (!stream.CanWrite)) {
throw new ArgumentException (
Locale.GetText ("Can't write on stream"));
}
_stream = stream;
_transform = transform;
_mode = mode;
_disposed = false;
if (transform != null) {
if (mode == CryptoStreamMode.Read) {
_currentBlock = new byte [transform.InputBlockSize];
_workingBlock = new byte [transform.InputBlockSize];
}
else if (mode == CryptoStreamMode.Write) {
_currentBlock = new byte [transform.OutputBlockSize];
_workingBlock = new byte [transform.OutputBlockSize];
}
}
}
示例2: PerformRandomizedTest
private static byte[] PerformRandomizedTest(ICryptoTransform expectedTransform, ICryptoTransform actualTransform,
byte[] vector)
{
using (var msExpected = new MemoryStream())
using (var msActual = new MemoryStream())
{
using (var csExpected = new CryptoStream(msExpected, expectedTransform, CryptoStreamMode.Write))
using (var csActual = new CryptoStream(msActual, actualTransform, CryptoStreamMode.Write))
{
byte[] bufferToTransform = vector;
if (bufferToTransform == null)
{
int randomBytesToGenerate = _WeakRandom.Next(0, MaxEncryptedSizeInBytes);
bufferToTransform = new byte[randomBytesToGenerate];
_WeakRandom.NextBytes(bufferToTransform);
}
csExpected.Write(bufferToTransform, 0, bufferToTransform.Length);
csActual.Write(bufferToTransform, 0, bufferToTransform.Length);
}
byte[] expectedTransformResult = msExpected.ToArray();
byte[] actualTransformResult = msActual.ToArray();
ByteUtilities.AssertBytesEqual(expectedTransformResult, actualTransformResult);
return expectedTransformResult;
}
}
示例3: CheckCBC
public void CheckCBC(ICryptoTransform encryptor, ICryptoTransform decryptor,
byte[] plaintext, byte[] expected)
{
if ((plaintext.Length % encryptor.InputBlockSize) != 0) {
throw new ArgumentException("Must have complete blocks");
}
byte[] ciphertext = new byte[plaintext.Length];
for (int i=0; i < plaintext.Length; i += encryptor.InputBlockSize) {
encryptor.TransformBlock(plaintext, i, encryptor.InputBlockSize, ciphertext, i);
}
for (int i=0; i<32; i++) {
AssertEquals("CBC-" + i, expected[i], ciphertext[i]);
}
byte[] roundtrip = new byte[plaintext.Length];
for (int i=0; i < ciphertext.Length; i += decryptor.InputBlockSize) {
decryptor.TransformBlock(ciphertext, i, decryptor.InputBlockSize, roundtrip, i);
}
for (int i=0; i<32; i++) {
AssertEquals("CBC-rt-" + i, roundtrip[i], plaintext[i]);
}
}
示例4: AuthenticationHelper
public AuthenticationHelper()
{
var rm = new RijndaelManaged();
encryptor = rm.CreateEncryptor(key, vector);
decryptor = rm.CreateDecryptor(key, vector);
encoder = new UTF8Encoding();
}
示例5: AesEncryption
public AesEncryption(byte[] Key, byte[] Vector)
{
RijndaelManaged rijndaelManaged = new RijndaelManaged();
this.EncryptorTransform = rijndaelManaged.CreateEncryptor(Key, Vector);
this.DecryptorTransform = rijndaelManaged.CreateDecryptor(Key, Vector);
this.UTFEncoder = new UTF8Encoding();
}
示例6: EncryptionHelper
// Methods
public EncryptionHelper()
{
RijndaelManaged managed = new RijndaelManaged();
this.EncryptorTransform = managed.CreateEncryptor(this.Key, this.Vector);
this.DecryptorTransform = managed.CreateDecryptor(this.Key, this.Vector);
this.UTFEncoder = new UTF8Encoding();
}
示例7: SetUp
public void SetUp()
{
using ( AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider() ) {
m_Encryptor = aesAlg.CreateEncryptor();
m_Decryptor = aesAlg.CreateDecryptor();
}
}
示例8: SimplerAES
public SimplerAES()
{
RijndaelManaged rm = new RijndaelManaged();
encryptor = rm.CreateEncryptor(key, vector);
decryptor = rm.CreateDecryptor(key, vector);
encoder = new UTF8Encoding();
}
示例9: AesEncryption
public AesEncryption(byte[] key, byte[] vector)
{
var rm = new RijndaelManaged();
_encryptor = rm.CreateEncryptor(key, vector);
_decryptor = rm.CreateDecryptor(key, vector);
_encoder = new UTF8Encoding();
}
示例10: AesDecoderStream
public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
{
mStream = input;
mLimit = limit;
// The 7z AES encoder/decoder classes do not perform padding, instead they require the input stream to provide a multiple of 16 bytes.
// If the exception below is thrown this means the 7z file is either corrupt or a newer 7z version has been published and we haven't updated yet.
if (((uint)input.Length & 15) != 0)
throw new NotSupportedException("7z requires AES streams to be properly padded.");
int numCyclesPower;
byte[] salt, seed;
Init(info, out numCyclesPower, out salt, out seed);
byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
byte[] key = InitKey(numCyclesPower, salt, password);
using (var aes = Aes.Create())
{
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
mDecoder = aes.CreateDecryptor(key, seed);
}
mBuffer = new byte[4 << 10];
}
示例11: Init
public static void Init(GraphicsDevice g, SpriteBatch s, ContentManager c)
{
graphics = g;
spriteBatch = s;
content = c;
font = content.Load<SpriteFont>("font\\CommonFont");
Random rand = new Random(13562538);
AesManaged aes = new AesManaged();
byte[] b_key = new byte[32];
byte[] b_iv = new byte[16];
rand.NextBytes(b_key);
rand.NextBytes(b_iv);
aes.Key = b_key;
aes.IV = b_iv;
decryptor = aes.CreateDecryptor();
state = State.Free;
waitall = false;
sleepTime = TimeSpan.Zero;
charas = new Dictionary<string, TalkChara>();
t_balloon = content.Load<Texture2D>("img\\face\\balloon");
t_balloon2 = content.Load<Texture2D>("img\\face\\balloon2");
}
示例12: ZipAESTransform
/// <summary>
/// Constructor.
/// </summary>
/// <param name="key">Password string</param>
/// <param name="saltBytes">Random bytes, length depends on encryption strength.
/// 128 bits = 8 bytes, 192 bits = 12 bytes, 256 bits = 16 bytes.</param>
/// <param name="blockSize">The encryption strength, in bytes eg 16 for 128 bits.</param>
/// <param name="writeMode">True when creating a zip, false when reading. For the AuthCode.</param>
///
public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode)
{
if (blockSize != 16 && blockSize != 32) // 24 valid for AES but not supported by Winzip
throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32.");
if (saltBytes.Length != blockSize / 2)
throw new Exception("Invalid salt len. Must be " + blockSize / 2 + " for blocksize " + blockSize);
// initialise the encryption buffer and buffer pos
_blockSize = blockSize;
_encryptBuffer = new byte[_blockSize];
_encrPos = ENCRYPT_BLOCK;
// Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c
var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS);
var rm = Aes.Create();
rm.Mode = CipherMode.ECB; // No feedback from cipher for CTR mode
_counterNonce = new byte[_blockSize];
byte[] byteKey1 = pdb.GetBytes(_blockSize);
byte[] byteKey2 = pdb.GetBytes(_blockSize);
_encryptor = rm.CreateEncryptor(byteKey1, byteKey2);
_pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH);
//
_hmacsha1 = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA1, byteKey2);
_writeMode = writeMode;
}
示例13: init
public override void init(int mode, byte[] key, byte[] iv)
{
m_mode = mode;
m_rijndael = new RijndaelManaged();
m_rijndael.Mode = CipherMode.CBC;
m_rijndael.Padding = PaddingMode.None;
byte[] tmp;
if (iv.Length > m_ivsize)
{
tmp = new byte[m_ivsize];
Array.Copy(iv, 0, tmp, 0, tmp.Length);
iv = tmp;
}
if (key.Length > m_bsize)
{
tmp = new byte[m_bsize];
Array.Copy(key, 0, tmp, 0, tmp.Length);
key = tmp;
}
try
{
m_cipher = (mode == ENCRYPT_MODE
? m_rijndael.CreateEncryptor(key, iv)
: m_rijndael.CreateDecryptor(key, iv)
);
}
catch (Exception)
{
m_cipher = null;
}
}
示例14: SimpleAES
public SimpleAES(byte[] encryptionKey, byte[] encryptionVector)
{
var rm = new RijndaelManaged();
_encryptor = rm.CreateEncryptor(encryptionKey, encryptionVector);
_decryptor = rm.CreateDecryptor(encryptionKey, encryptionVector);
_encoder = new UTF8Encoding();
}
示例15: CryptographyService
public CryptographyService()
{
var rm = new RijndaelManaged();
_encryptor = rm.CreateEncryptor(Key, Vector);
_decryptor = rm.CreateDecryptor(Key, Vector);
_encoder = new UTF8Encoding();
}