什么加密模式/填充违约或AES加密常见的用途将与.NET使用吗? [英] What cipher mode/padding defaults or common uses of AES encryption would be used with .NET?

查看:155
本文介绍了什么加密模式/填充违约或AES加密常见的用途将与.NET使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在帮助别人,需要与AES发送加密的价值给客户。客户没有指定的块加密模式,填充或如何生成密钥。他们已经只说这样的:

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:

然后,加密使用AES此字符串   加密与256的按键尺寸,   长度为零(或长度为16的矢量   字节数组如果DOTNET)和键   XXX。

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".

其中XXX关键是19个字符。我假设他们使用.NET因为它提到。有谁熟悉.NET知道他们可能会建议做的只是一个19字符的字符串键?我们很熟悉加密和将要使用的Java就在我们身边。但是没有办法知道如何构造函数中的AES密钥和密码是什么模式和填充使用,我们不能再往前走。客户没有响应非常迅速地对我们的问题,所以我想我会试着问这里。谢谢!

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中,它接受一个字符串作为重点。键被指定为字节数组,使得数组的长度等于密钥大小/ 8

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.

人们希望他们将使用一个共同的散列算法,以产生从19字符串的关键。最好的选择将可能是一个字符串的SHA256哈希值。

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.

只给你那是什么样子的。NET ...

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

      }

这篇关于什么加密模式/填充违约或AES加密常见的用途将与.NET使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆