Esempio n. 1
0
        /// <summary>
        /// Get's deep copy of Key from IKeyset
        /// </summary>
        /// <param name="keySet">The keyset.</param>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        public static Key GetKey(this IKeySet keySet, int version)
        {
            var keyData = keySet.GetKeyData(version);
            var key     = Key.Read(keySet.Metadata.KeyType, keyData);

            keyData.Clear();
            return(key);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MutableKeySet"/> class.
        /// </summary>
        /// <param name="keySet">The key set.</param>
        public MutableKeySet(IKeySet keySet)
        {
            _metadata = keySet.Metadata;

            foreach (var version in keySet.Metadata.Versions)
            {
                //Easy way to deep copy keys
                var keyData = keySet.GetKeyData(version.VersionNumber);
                var key     = Key.Read(_metadata.KeyType, keyData);
                keyData.Clear();
                _keys.Add(version.VersionNumber, key);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MutableKeySet"/> class.
        /// </summary>
        /// <param name="keySet">The key set.</param>
        public MutableKeySet(IKeySet keySet)
        {
            _metadata = keySet.Metadata;

            foreach (var version in keySet.Metadata.Versions)
            {
                //Easy way to deep copy keys
                var keyData = keySet.GetKeyData(version.VersionNumber);
                var key = Key.Read(_metadata.KeyType, keyData);
                keyData.Clear();
                _keys.Add(version.VersionNumber, key);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the binary data that the key is stored in.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        public byte[] GetKeyData(int version)
        {
            var cipherData = _keySet.GetKeyData(version);

            if (!Metadata.Encrypted)
            {
                return(cipherData);
            }

            var cipherString = Keyczar.RawStringEncoding.GetString(cipherData);

            return(_crypter.Decrypt(WebSafeBase64.Decode(cipherString.ToCharArray())));
        }
Esempio n. 5
0
        public byte[] GetKeyData(int version)
        {
            var data       = _keySet.GetKeyData(version);
            var jsonString = this.GetConfig().RawStringEncoding.GetString(data);
            var pack       = JsonConvert.DeserializeObject <SessionPack>(jsonString);



            using (var sessionCrypter = new SessionCrypter(_crypter, pack.SessionMaterial, keyPacker: _sessionPacker))
            {
                return(sessionCrypter.Decrypt(pack.CipherText));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the binary data that the key is stored in.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        public byte[] GetKeyData(int version)
        {
            var cipherData = _keySet.GetKeyData(version);

            if (!Metadata.Encrypted)
            {
                return(cipherData);
            }

            var cipherString = this.GetConfig().RawStringEncoding.GetString(cipherData);
            var store        = JsonConvert.DeserializeObject <PbeKeyStore>(cipherString);

            return(store.DecryptKeyData(_password.Prompt));
        }