ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Properties | List of all members
ImageResizer.Plugins.Security.SimpleSecureEncryption Class Reference

Provides correct 256-bit AES encryption and decryption for small data sets. More...

Public Member Functions

 SimpleSecureEncryption (byte[] keyBasis)
 Creates an encryption/decryption system using a 256-bit key derived from the specified byte sequence. 32-bit or longer phrases are suggested. More...
 
 SimpleSecureEncryption (string passPhrase)
 Creates an encryption/decryption system using a 256-bit key derived from the specified pass phrase. 32-bit or longer phrases are suggested. More...
 
byte[] Decrypt (byte[] data, byte[] iv)
 Decrypts the specified data using a derived key and the specified IV More...
 
byte[] Encrypt (byte[] data, out byte[] iv)
 Encrypts the specified data using a derived key and a generated IV. More...
 

Properties

int KeySizeInBytes [get]
 The number of bytes in the key - defaults to 32 (256-bit AES) More...
 
int BlockSizeInBytes [get]
 The number of bytes in a single block. Also the size of the IV (Initialization Vector). More...
 

Detailed Description

Provides correct 256-bit AES encryption and decryption for small data sets.

Definition at line 13 of file SimpleSecureEncryption.cs.

Constructor & Destructor Documentation

ImageResizer.Plugins.Security.SimpleSecureEncryption.SimpleSecureEncryption ( byte[]  keyBasis)
inline

Creates an encryption/decryption system using a 256-bit key derived from the specified byte sequence. 32-bit or longer phrases are suggested.

Parameters
keyBasisA password or key

Definition at line 19 of file SimpleSecureEncryption.cs.

19  {
20  this.keyBasis = keyBasis;
21  }
ImageResizer.Plugins.Security.SimpleSecureEncryption.SimpleSecureEncryption ( string  passPhrase)
inline

Creates an encryption/decryption system using a 256-bit key derived from the specified pass phrase. 32-bit or longer phrases are suggested.

Parameters
passPhrase

Definition at line 26 of file SimpleSecureEncryption.cs.

26  {
27  this.keyBasis = UTF8Encoding.UTF8.GetBytes(passPhrase);
28  }

Member Function Documentation

byte [] ImageResizer.Plugins.Security.SimpleSecureEncryption.Decrypt ( byte[]  data,
byte[]  iv 
)
inline

Decrypts the specified data using a derived key and the specified IV

Parameters
data
iv
Returns

Definition at line 75 of file SimpleSecureEncryption.cs.

75  {
76  if (iv.Length != BlockSizeInBytes) throw new ArgumentOutOfRangeException("The specified IV is invalid - an " + BlockSizeInBytes + " byte array is required.");
77 
78  var rm = GetAlgorithm();
79  try {
80  using (var decrypt = rm.CreateDecryptor(GetKey(), iv))
81  using (var ms = new MemoryStream(data, 0, data.Length, false, true))
82  using (var s = new CryptoStream(ms, decrypt, CryptoStreamMode.Read)) {
83  return StreamExtensions.CopyToBytes(s);
84 
85  }
86  } finally {
87  rm.Clear();
88  }
89 
90  }
int BlockSizeInBytes
The number of bytes in a single block. Also the size of the IV (Initialization Vector).
byte [] ImageResizer.Plugins.Security.SimpleSecureEncryption.Encrypt ( byte[]  data,
out byte[]  iv 
)
inline

Encrypts the specified data using a derived key and a generated IV.

Parameters
data
iv
Returns

Definition at line 98 of file SimpleSecureEncryption.cs.

98  {
99  var rm = GetAlgorithm();
100  try {
101  rm.GenerateIV();
102  iv = rm.IV;
103  rm.Key = GetKey();
104  using (var encrypt = rm.CreateEncryptor())
105  using (var ms = new MemoryStream(data.Length / BlockSizeInBytes)) {
106  using (var s = new CryptoStream(ms, encrypt, CryptoStreamMode.Write)) {
107  s.Write(data, 0, data.Length);
108  s.Flush();
109  s.FlushFinalBlock();
110  ms.Seek(0, SeekOrigin.Begin);
111  return StreamExtensions.CopyToBytes(ms);
112  }
113  }
114  } finally {
115  rm.Clear();
116  }
117  }
int BlockSizeInBytes
The number of bytes in a single block. Also the size of the IV (Initialization Vector).

Property Documentation

int ImageResizer.Plugins.Security.SimpleSecureEncryption.BlockSizeInBytes
get

The number of bytes in a single block. Also the size of the IV (Initialization Vector).

Definition at line 47 of file SimpleSecureEncryption.cs.

int ImageResizer.Plugins.Security.SimpleSecureEncryption.KeySizeInBytes
get

The number of bytes in the key - defaults to 32 (256-bit AES)

Definition at line 40 of file SimpleSecureEncryption.cs.


The documentation for this class was generated from the following file: