I've written an encryption routine built from several methods on the net. I'm currently testing the encryption and have noticed that every encrypted value end in '==' ?
Does anyone know why this might be the case ?
This is the code I'm using. The key is a 32 char value and the IV is a 16 char value.
private static readonly byte[] key = Encoding.Default.GetBytes(getKey());
private static readonly byte[] iv = Encoding.Default.GetBytes("$ruVe4E!eM#kupuc");
/// <summary>
///
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public static string Encrypt(string val)
{
string result = string.Empty;
var aes = getEncryptionType();
using (MemoryStream msEncrypt = new MemoryStream())
{
using (ICryptoTransform encryptor = aes.CreateEncryptor(key, iv))
{
using(CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using(StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(val);
}
}
}
result = Convert.ToBase64String(msEncrypt.ToArray());
}
aes.Clear();
return result;
}
getEncryptionType returns an AESManaged class as below:
private static AesManaged getEncryptionType()
{
AesManaged aes = new AesManaged();
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
return aes;
}
Currently the test method looks like this:
Random rnd = new Random();
for (int i = 0; i < 50000; i++)
{
int random = rnd.Next(1147483647, int.MaxValue);
Guid guid = dal.getToken(CryptoService.Encrypt(random.ToString()));
if (i % 100 == 0)
addLog(string.Format("{0} new values added", i.ToString()), LogType.Dialog);
}
AES 256 is virtually impenetrable using brute-force methods. While a 56-bit DES key can be cracked in less than a day, AES would take billions of years to break using current computing technology. Hackers would be foolish to even attempt this type of attack.
With the right quantum computer, AES-128 would take about 2.61*10^12 years to crack, while AES-256 would take 2.29*10^32 years. For reference, the universe is currently about 1.38×10^10 years old, so cracking AES-128 with a quantum computer would take about 200 times longer than the universe has existed.
Although AES key lengths – 128, 192, and 256 bits – may change, the block size of the data encrypted with AES is always 128 bits in size. Out of 128-bit, 192-bit, and 256-bit AES encryption, which progressively use more rounds of encryption for improved security, 128-bit AES encryption is technically the least secure.
The AES Encryption algorithm (also known as the Rijndael algorithm) is a symmetric block cipher algorithm with a block/chunk size of 128 bits. It converts these individual blocks using keys of 128, 192, and 256 bits. Once it encrypts these blocks, it joins them together to form the ciphertext.
That is standard for base 64 encoding. Read the "padding" section of the Wikipedia article for details.
http://en.wikipedia.org/wiki/Base64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With