JoshuaJeanThree
JoshuaJeanThree

Reputation: 1392

AES Encryption KEY conversion from python key to C#

I have a file encrypted with AES in python and its key is defined in code as:

key = '\x14\x15\xa2\xf6\xb6\x17\x4a\x58\xb6\x17\x4a\x58\xb6\x17\x4a\x58'
#print binascii.hexlify(key)
aes = AES.new(key, AES.MODE_ECB)

However my C# code takes key parameter as something like "skey = 1234512345678976"

private static void EncryptFile(string inputFile, string outputFile, string skey)
        {
            try
            {
                using (RijndaelManaged aes = new RijndaelManaged())
                {
                    byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
                    ....
                }
            }
         }

So, how can I decrypt these files according to the same key? What is the equivalent of python key in C#? I am using C# code lies in here: http://www.fluxbytes.com/csharp/encrypt-and-decrypt-files-in-c/

Upvotes: 0

Views: 366

Answers (1)

Zeus82
Zeus82

Reputation: 6375

I don't think you want to do ASCIIEncoding.UTF8.GetBytes(skey), you need to treat the key as if it was a hex string and convert it as such. See:

How can I convert a hex string to a byte array?

Upvotes: 1

Related Questions