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("?"); }
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("?"); }
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); }
internal HmacKey( SafeCryptoKeyHandle keyHandle, string algorithmName, int outputLength) : base(keyHandle) { DigestAlgorithm = new SubtleHashAlgorithm(algorithmName); OutputLength = outputLength; }
public void Dispose() { KeyHandle?.Dispose(); KeyHandle = null; }
private protected CryptoKey(SafeCryptoKeyHandle keyHandle) { KeyHandle = keyHandle; }
internal AesCbc(SafeCryptoKeyHandle keyHandle, string algorithmName) : base(keyHandle, algorithmName) { }
private protected SymmetricKey(SafeCryptoKeyHandle keyHandle, string algorithmName) : base(keyHandle) { AlgorithmName = algorithmName; }