Пример #1
0
        /// <summary>
        /// Stores the specified instance of <see cref="KeyEntry"/>.
        /// </summary>
        /// <param name="entry">The instance of <see cref="KeyEntry"/>.</param>
        /// <exception cref="DuplicateKeyException"></exception>
        public void Store(KeyEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }
            var keyEntryData = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(new KeyEntryData()
            {
                Meta = entry.Meta, Value = entry.Value
            }));

            coreStorage.Save(entry.Name, keyEntryData);
        }
Пример #2
0
        /// <summary>
        /// Saves a current <see cref="VirgilKey"/> in secure storage.
        /// </summary>
        /// <param name="keyName">The name of the key.</param>
        /// <param name="password">The password (optional).</param>
        public VirgilKey Save(string keyName, string password = null)
        {
            var exportedPrivateKey = this.context.Crypto.ExportPrivateKey(this.privateKey, password);
            var keyEntry           = new KeyEntry
            {
                Name  = keyName,
                Value = exportedPrivateKey
            };

            if (this.context.KeyStorage.Exists(keyEntry.Name))
            {
                throw new VirgilKeyIsAlreadyExistsException();
            }

            this.context.KeyStorage.Store(keyEntry);
            return(this);
        }