I am trying to use BouncyCastle's AES Key Wrap in order to carry out deterministic encryption. But I am getting the following error:
Org.BouncyCastle.Crypto.DataLengthException: 'wrap data must be a multiple of 8 bytes'
Here is my code:
static void Main(string[] args)
{
var txt = UTF8Encoding.UTF8.GetBytes("Some text here.");
var key = UTF8Encoding.UTF8.GetBytes("aaaaaaaaaaaaaaaa");
var encyptedBytes = Wrap(key, txt);
}
public static byte[] Wrap(byte[] kek, byte[] plaint)
{
var en = new AesWrapEngine();
en.Init(true, new KeyParameter(kek));
return en.Wrap(plaint, 0, plaint.Length);
}
public static byte[] Unwrap(byte[] kek, byte[] ciphert)
{
var en = new AesWrapEngine();
en.Init(false, new KeyParameter(kek));
return en.Unwrap(ciphert, 0, ciphert.Length);
}
How can I make it work for an input of any size?
question from:
https://stackoverflow.com/questions/65903455/bouncycastle-aes-key-wrap-multiple-of-8-bytes-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…