Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
90 views
in Technique[技术] by (71.8m points)

c# - BouncyCastle AES Key Wrap - multiple of 8 bytes error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...