malgia / slowaes

Automatically exported from code.google.com/p/slowaes
0 stars 0 forks source link

trying to create a working output against known config #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello-

I have a few reference implementations of AES-256-CBC in C#, Ruby, PHP, and 
Flash.

I am know trying to get it to talk to JS via slow aes using the same settings.

I've been toiling for hours trying to get it to work, so I thought I'd ask to 
see if anyone had any ideas.

On a working system, using the following settings:

IV = 0123456789012345
key = 67a4f45f0d1d9bc606486fc42dc49416
plaintext = yay!

Across my reference implementations, I get the following Base64 encoded output:

q/xJqqN6qbiZMXYmiQC1Fw==

I am having trouble setting up slowaes to give me the same. Can anyone give me 
some pointers?

tia

Original issue reported on code.google.com by ger...@pubnub.com on 14 Nov 2012 at 6:05

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
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