我有这个代码:
RijndaelManaged rijndaelCipher = new RijndaelManaged();
// Set key and IV
rijndaelCipher.Key = Convert.FromBase64String("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912");
rijndaelCipher.IV = Convert.FromBase64String("1234567890123456789012345678901234567890123456789012345678901234");
Run Code Online (Sandbox Code Playgroud)
我被抛出:
Specified key is not a valid size for this algorithm.
Specified initialization vector (IV) does not match the block size for this algorithm.
Run Code Online (Sandbox Code Playgroud)
这个字符串出了什么问题?我能算一下你的一些例子吗?
对c#来说很新,目前在解密长密码时遇到问题,错误是
指定的密钥不是此算法的有效大小
我知道这与加密密码位长度不受支持有关,但不确定如何建议允许这些更长密码的方法.
这是我的加密和解密
"cipherKey":"0123456789abcdef","cipherVector":"somereallycooliv"
using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace DataApi
{
public class Encryption
{
private readonly IConfigurationService _configService;
private const string _vector = "cipherVector";
private const string _key = "cipherKey";
public Encryption(IConfigurationService configService)
{
_configService = configService;
}
public string EncryptString(string text)
{
if(string.IsNullOrEmpty(text))
{
return "";
}
try
{
var key = Encoding.UTF8.GetBytes(_configService.Get(_key));
byte[] IV = Encoding.ASCII.GetBytes(_configService.Get(_vector));
using (var aesAlg = Aes.Create())
{
using (var encryptor = aesAlg.CreateEncryptor(key, IV))
{
using (var msEncrypt …Run Code Online (Sandbox Code Playgroud)