Пример #1
0
        private async Task <T> GenerateRsaKeyAsync <T>(
            int keySize,
            string algorithmName,
            string hashAlgorithmName,
            bool signatureKey,
            Func <SafeCryptoKeyHandle, string, string, T> ctor)
        {
            bool?result;
            IJSObjectReference module = await GetModule();

            string keyId;

            do
            {
                keyId  = Guid.NewGuid().ToString("N");
                result = await module.InvokeAsync <bool?>(
                    "generateRsaKey",
                    keySize,
                    keyId,
                    algorithmName,
                    hashAlgorithmName,
                    signatureKey);
            } while (!result.HasValue);

            if (result.GetValueOrDefault())
            {
                SafeCryptoKeyHandle handle = new SafeCryptoKeyHandle(keyId, module);
                return(ctor(handle, algorithmName, hashAlgorithmName));
            }

            throw new Exception("?");
        }
Пример #2
0
        private async Task <HmacKey> ImportHmacKeyAsync(
            string algorithmName,
            int outputLength,
            ReadOnlyMemory <byte> key)
        {
            bool?result;
            IJSObjectReference module = await GetModule();

            string keyId;

            do
            {
                keyId  = Guid.NewGuid().ToString("N");
                result = await module.InvokeAsync <bool?>(
                    "importHmacKey",
                    Convert.ToBase64String(key.Span),
                    keyId,
                    algorithmName);
            } while (!result.HasValue);

            if (result.GetValueOrDefault())
            {
                SafeCryptoKeyHandle handle = new SafeCryptoKeyHandle(keyId, module);
                return(new HmacKey(handle, algorithmName, outputLength));
            }

            throw new Exception("?");
        }
Пример #3
0
        private async Task <T> ImportSymmetricKeyAsync <T>(
            byte[] key,
            string algorithmName,
            Func <SafeCryptoKeyHandle, string, T> ctor)
        {
            bool?result;
            IJSObjectReference module = await GetModule();

            string keyId;

            do
            {
                keyId  = Guid.NewGuid().ToString("N");
                result = await module.InvokeAsync <bool?>(
                    "importSecretKey",
                    Convert.ToBase64String(key),
                    keyId,
                    algorithmName);
            } while (!result.HasValue);

            if (result.GetValueOrDefault())
            {
                SafeCryptoKeyHandle handle = new SafeCryptoKeyHandle(keyId, module);
                return(ctor(handle, algorithmName));
            }

            throw new Exception("?");
        }
 internal RsaPkcs1SignatureKey(
     SafeCryptoKeyHandle keyHandle,
     string algorithmName,
     string hashAlg)
     : base(keyHandle, algorithmName)
 {
     HashAlgorithm = new SubtleHashAlgorithm(hashAlg);
 }
Пример #5
0
 internal HmacKey(
     SafeCryptoKeyHandle keyHandle,
     string algorithmName,
     int outputLength)
     : base(keyHandle)
 {
     DigestAlgorithm = new SubtleHashAlgorithm(algorithmName);
     OutputLength    = outputLength;
 }
Пример #6
0
 public void Dispose()
 {
     KeyHandle?.Dispose();
     KeyHandle = null;
 }
Пример #7
0
 private protected CryptoKey(SafeCryptoKeyHandle keyHandle)
 {
     KeyHandle = keyHandle;
 }
Пример #8
0
 internal AesCbc(SafeCryptoKeyHandle keyHandle, string algorithmName)
     : base(keyHandle, algorithmName)
 {
 }
Пример #9
0
 private protected SymmetricKey(SafeCryptoKeyHandle keyHandle, string algorithmName)
     : base(keyHandle)
 {
     AlgorithmName = algorithmName;
 }