Open GoogleCodeExporter opened 8 years ago
Here is a more concise example. Given this example in C#:
private string EncryptOrDecrypt(bool type, string plainStr)
{
RijndaelManaged aesEncryption = new RijndaelManaged();
aesEncryption.KeySize = 256;
aesEncryption.BlockSize = 128;
aesEncryption.Mode = CipherMode.CBC;
aesEncryption.Padding = PaddingMode.PKCS7;
//get ASCII bytes of the string
aesEncryption.IV = System.Text.Encoding.ASCII.GetBytes("0123456789012345");
aesEncryption.Key = System.Text.Encoding.ASCII.GetBytes("67a4f45f0d1d9bc606486fc42dc49416");
if (type)
{
ICryptoTransform crypto = aesEncryption.CreateEncryptor();
plainStr = EncodeNonAsciiCharacters(plainStr);
byte[] plainText = Encoding.ASCII.GetBytes(plainStr);
//encrypt
byte[] cipherText = crypto.TransformFinalBlock(plainText, 0, plainText.Length);
return Convert.ToBase64String(cipherText);
}
else
{
ICryptoTransform decrypto = aesEncryption.CreateDecryptor();
//decode
byte[] decryptedBytes = Convert.FromBase64CharArray(plainStr.ToCharArray(), 0, plainStr.Length);
//decrypt
string strDecrypted = System.Text.Encoding.ASCII.GetString(decrypto.TransformFinalBlock(decryptedBytes, 0, decryptedBytes.Length));
return strDecrypted;
}
}
How would I convert this to it's slow AES equiv?
I'm specifically having issues figuring out how to convert the strings into
their byte array equivs using slowaes.
tia
Original comment by ger...@pubnub.com
on 15 Nov 2012 at 3:40
FWIW, I got this working using gibberish-aes as follows:
GibberishAES.size(256);
var password = GibberishAES.s2a("67a4f45f0d1d9bc606486fc42dc49416");
var iv = GibberishAES.s2a("0123456789012345");
var plaintext = GibberishAES.s2a("yay!");
GibberishAES.Base64.encode(enc);
For those wondering what s2a is doing:
s2a = function(string, binary) {
var array = [], i;
if (! binary) {
string = enc_utf8(string);
}
for (i = 0; i < string.length; i++)
{
array[i] = string.charCodeAt(i);
}
return array;
}
Knowing how to do the equivalent in slowaes would be valuable as well.
tia
Original comment by ger...@pubnub.com
on 15 Nov 2012 at 4:47
Original issue reported on code.google.com by
ger...@pubnub.com
on 14 Nov 2012 at 6:05