/// <summary>
        /// Persists new key in storage.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Task StoreKeyAsync(SerializedKey key)
        {
            var json = KeySerializer.Serialize(key, EncodeJson);

            var path = Path.Combine(_directory.FullName, KeyFilePrefix + key.Id + KeyFileExtension);

            File.WriteAllText(path, json, Encoding.UTF8);

            return(Task.CompletedTask);
        }
Exemple #2
0
        /// <summary>
        /// Protects RsaKeyContainer.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public SerializedKey Protect(RsaKeyContainer key)
        {
            var data = KeySerializer.Serialize(key);

            if (_options.DataProtectKeys)
            {
                data = _dataProtectionProvider.Protect(data);
            }

            return(new SerializedKey
            {
                Created = DateTime.UtcNow,
                Id = key.Id,
                KeyType = key.KeyType,
                Data = data,
                DataProtected = _options.DataProtectKeys,
            });
        }
        /// <inheritdoc/>
        public SerializedKey Protect(KeyContainer key)
        {
            var data = KeySerializer.Serialize(key);

            if (_options.DataProtectKeys)
            {
                data = _dataProtectionProvider.Protect(data);
            }

            return(new SerializedKey
            {
                Version = 1,
                Created = DateTime.UtcNow,
                Id = key.Id,
                Algorithm = key.Algorithm,
                IsX509Certificate = key.HasX509Certificate,
                Data = data,
                DataProtected = _options.DataProtectKeys,
            });
        }