Exemplo n.º 1
0
        public void WrapKey_Failure()
        {
            var keyEncryptionKey = SymmetricJwk.GenerateKey(128);
            var wrapper          = new AesKeyWrapper(keyEncryptionKey.K, EncryptionAlgorithm.A256CbcHS512, KeyManagementAlgorithm.A128KW);
            var destination      = new byte[0];
            var header           = new JwtHeader();

            Assert.Throws <ArgumentException>(() => wrapper.WrapKey(null, header, destination));

            Assert.Equal(0, header.Count);
        }
Exemplo n.º 2
0
        public void WrapUnwrap()
        {
            var kwp = new AesKeyWrapper(_key, EncryptionAlgorithm.Aes128CbcHmacSha256, KeyManagementAlgorithm.Aes128KW);

            byte[] wrappedKey = new byte[kwp.GetKeyWrapSize()];
            var    cek        = kwp.WrapKey(_keyToWrap, null, wrappedKey);

            var kuwp         = new AesKeyUnwrapper(_key, EncryptionAlgorithm.Aes128CbcHmacSha256, KeyManagementAlgorithm.Aes128KW);
            var unwrappedKey = new byte[kuwp.GetKeyUnwrapSize(wrappedKey.Length)];
            var unwrapped    = kuwp.TryUnwrapKey(wrappedKey, unwrappedKey, null, out int keyWrappedBytesWritten);

            Assert.True(unwrapped);
        }