/// <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()))); }
private void EncodeData(Stream outstream, string destination) { var memstream = (MemoryStream)outstream; outstream.Flush(); var encodedOutput = WebSafeBase64.Encode(memstream.ToArray()); if (String.IsNullOrWhiteSpace(destination)) { Console.Write(encodedOutput); } else { if (File.Exists(destination)) { throw new Exception("File already Exists!!"); } File.WriteAllText(destination, new string(encodedOutput)); } }
/// <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); }