使用AesManaged进行CTR加密

时间:2018-10-02 13:59:18

标签: c# encryption aes

我正在尝试使用此代码https://gist.github.com/hanswolff/8809275进行CTR加密/解密。但是当我加密然后解密时,我不会得到我的纯文本。我找到了对该代码的一些引用,从注释中看,这似乎是一个不错的实现。那我在做什么错了?

byte[] initialCounter = new byte[] { 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF };
    byte[] Key = new byte[] { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
    byte[] data = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

    aes128CounterMode = new Aes128CounterMode(initialCounter);
    encryptor = aes128CounterMode.CreateEncryptor(Key, null);
    decryptor = aes128CounterMode.CreateDecryptor(Key, null);

    encryptor.TransformBlock(data, 0, 16, endata, 0);     
    decryptor.TransformBlock(endata, 0, 16, roundTrip, 0);

0 个答案:

没有答案