Ejemplo n.º 1
0
        public AesKeyUnwrapper(ReadOnlySpan <byte> key, EncryptionAlgorithm encryptionAlgorithm, KeyManagementAlgorithm algorithm)
            : base(encryptionAlgorithm, algorithm)
        {
            Debug.Assert(SymmetricJwk.SupportedKeyManagement(key.Length << 3, algorithm));
            Debug.Assert(algorithm.Category == AlgorithmCategory.Aes);
#if SUPPORT_SIMD
            if (System.Runtime.Intrinsics.X86.Aes.IsSupported && EncryptionAlgorithm.EnabledAesInstructionSet)
            {
                if (algorithm == KeyManagementAlgorithm.A128KW)
                {
                    _decryptor = new Aes128BlockDecryptor(key);
                }
                else if (algorithm == KeyManagementAlgorithm.A256KW)
                {
                    _decryptor = new Aes256BlockDecryptor(key);
                }
                else if (algorithm == KeyManagementAlgorithm.A192KW)
                {
                    _decryptor = new Aes192BlockDecryptor(key);
                }
                else
                {
                    ThrowHelper.ThrowNotSupportedException_AlgorithmForKeyWrap(algorithm);
#if NET5_0_OR_GREATER
                    Unsafe.SkipInit(out _decryptor);
#else
                    _decryptor = new Aes128BlockDecryptor(default);