Exemplo n.º 1
0
 public void Write(byte[] keyData, int version)
 {
     using (var sessionCrypter = new SessionCrypter(_encrypter, keySize: 256,
                                                    symmetricKeyType: UnofficialKeyType.AesAead, keyPacker: _sessionPacker))
     {
         var sessionMaterial = sessionCrypter.SessionMaterial;
         var cipherData      = sessionCrypter.Encrypt(keyData);
         var session         = new CertEncryptedKeySet.SessionPack(sessionMaterial, cipherData);
         var json            = Keyczar.Util.Utility.ToJson(session);
         var jsonData        = this.GetConfig().RawStringEncoding.GetBytes(json);
         _writer.Write(jsonData, version);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Saves using the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <returns>true if successful</returns>
        public bool Save(IKeySetWriter writer)
        {
            writer.Write(_metadata);

            if (!onlyMetaChanged || writer is INonSeparatedMetadataAndKey)
            {
                for (int i = 1; i <= _keys.Count; i++)
                {
                    var key = _keys[i];
                    writer.Write(key, i);
                }
            }
            return(writer.Finish());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the specified key data.
        /// </summary>
        /// <param name="keyData">The key data.</param>
        /// <param name="version">The version.</param>
        public void Write(byte[] keyData, int version)
        {
            var keyStore = PbeKeyStore.EncryptKeyData(keyData, _password.Prompt, _iterationCount);

            _writer.Write(this.GetConfig().RawStringEncoding.GetBytes(keyStore.ToJson()), version);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Saves using the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <returns>true if successful</returns>
        public bool Save(IKeySetWriter writer)
        {
            writer.Write(_metadata);

            if (!onlyMetaChanged || writer is INonSeparatedMetadataAndKey)
            {
                for (int i = 1; i <= _keys.Count; i++)
                {
                    var key = _keys[i];
                    writer.Write(key, i);
                }
            }
            return writer.Finish();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Writes the specified key.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="key">The key.</param>
 /// <param name="version">The version.</param>
 public static void Write(this IKeySetWriter writer, Key key, int version)
 {
     writer.Write(writer.GetConfig().RawStringEncoding.GetBytes(key.ToJson()), version);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Writes the specified key data.
        /// </summary>
        /// <param name="keyData">The key data.</param>
        /// <param name="version">The version.</param>
        public void Write(byte[] keyData, int version)
        {
            var cipherData = _encrypter.Encrypt(keyData);

            _writer.Write(Keyczar.RawStringEncoding.GetBytes(WebSafeBase64.Encode(cipherData)), version);
        }