예제 #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;
 }