Exemple #1
0
        public void Encrypt(Span <byte> input, int packetCounter, Span <byte> output, Span <byte> tag)
        {
            if (!_threadInitialized)
            {
                _nounceBuffer = new byte[12];
            }
            // turn counter into an array
            _nounceBuffer[8]  = (byte)(packetCounter << 24);
            _nounceBuffer[9]  = (byte)(packetCounter << 16);
            _nounceBuffer[10] = (byte)(packetCounter << 8);
            _nounceBuffer[11] = (byte)packetCounter;

            _aesGcm.Encrypt(_nounceBuffer, input, output, tag);
        }
Exemple #2
0
        public void EncryptSameResultAsDotNetStandard()
        {
            byte[] plainText = new byte[] { 0xf5, 0x6e, 0x87, 0x05, 0x5b, 0xc3, 0x2d, 0x0e, 0xeb, 0x31, 0xb2, 0xea, 0xcc, 0x2b, 0xf2, 0xa5 };
            var    nonce     = new byte[12] {
                0x99, 0xaa, 0x3e, 0x68, 0xed, 0x81, 0x73, 0xa0, 0xee, 0xd0, 0x66, 0x84
            };

            byte[] cipherText = new byte[16];
            byte[] tag        = new byte[16];
            _aesGcm.Encrypt(nonce, plainText, cipherText, tag);

            using (var aesGcmDotnetStandard = new System.Security.Cryptography.AesGcm(_key))
            {
                byte[] expectedCipherText = new byte[16];
                byte[] expectedTag        = new byte[16];
                aesGcmDotnetStandard.Encrypt(nonce, plainText, expectedCipherText, expectedTag);

                CollectionAssert.AreEqual(expectedCipherText, cipherText);
                CollectionAssert.AreEqual(expectedTag, tag);
            }
        }