What cipher mode/padding defaults or common uses o

2020-05-06 06:53发布

I'm helping someone that needs to send an encrypted value with AES to a customer. The customer has not specified the block cipher mode, padding or how to generate the key. They've only said this:

Then, encrypt this string using AES encryptions with a key size of 256, a vector of length zero (or length 16 byte array if in dotnet) and the key of "XXX".

Of which the XXX key is 19 characters. I'm assuming that they're using .NET since it's mentioned. Does anyone familiar with .NET know what they might be suggesting to do with just a 19 character string for the key? We're familiar with encryption and will be using Java on our side. However without a way to know how to constructor the AES key and what cipher mode and padding to use, we can't go any further. The customer is not responding very quickly to our questions, so I thought I'd try asking here. Thanks!

标签: .net
1条回答
在下西门庆
2楼-- · 2020-05-06 07:48

There's no constructor for or method in any of the Aes classes in .net that takes in a string as a key. Keys are specified as an array of bytes, such that the length of the array is equal to the key size / 8.

One would hope that they would use a common hash algorithm to generate the key from the 19 character string. Best bet would probably be a Sha256 hash of the string.

Just to give you an idea of what that would look like in .net ...

public void InitializeCrypto()
      {
           var utf8 = new UTF8Encoding();
           var hash = new SHA256CryptoServiceProvider();
           var aes = new AesCryptoServiceProvider();
           var iv = new byte[16];

           Array.Clear(iv, 0, iv.Length);
           string key = "Some19CharacterString";
           var utf8Bytes = utf8.GetBytes(key);
           aes.IV = iv;
           aes.KeySize = 256;
           aes.Key = hash.ComputeHash(utf8Bytes);
           //Do crypto work

      }
查看更多
登录 后发表回答