Exemple #1
0
 string PGPEncryptToASCIIArmored(byte[] data, string filename = "encrypted-data.gpg")
 {
     using (var encOut = new MemoryStream()) {
         var byteData = GPGTools.EncryptForKeys(data, keys, filename);
         var s        = new ArmoredOutputStream(encOut);
         s.Write(byteData, 0, byteData.Length);
         s.Close();
         encOut.Seek(0, SeekOrigin.Begin);
         var reader = new StreamReader(encOut);
         return(reader.ReadToEnd());
     }
 }
Exemple #2
0
        public FieldDecipherPacket DecipherPacket(FieldCipherPacket packet)
        {
            var encryptedKey = Convert.FromBase64String(packet.EncryptedKey);
            var keyData      = GPGTools.Decrypt(encryptedKey, key);
            var baseKey      = Convert.FromBase64String(keyData.Base64Data);

            var encryptedJson = packet.EncryptedJSON;
            var result        = DecryptJsonFields(encryptedJson, baseKey);

            return(new FieldDecipherPacket {
                UnmatchedFields = result.Item2,
                DecryptedData = result.Item1,
            });
        }
Exemple #3
0
 public Decipher(string gpgPrivateKey)
 {
     secret  = GPGTools.LoadSecretKey(gpgPrivateKey);
     matcher = new Regex(FieldRegex, RegexOptions.IgnoreCase);
 }
Exemple #4
0
 public string PGPEncryptToBase64(byte[] data, string filename = "encrypted-data.gpg")
 {
     return(Convert.ToBase64String(GPGTools.EncryptForKeys(data, keys, filename)));
 }
Exemple #5
0
 public Cipher(List <string> gpgPubKey)
 {
     keys = gpgPubKey.Select((a) => GPGTools.LoadPublicKeyFromString(a)).ToList();
     sr   = new SecureRandom();
 }