private OpenPgpSignature Verify([NotNull] byte[] data, [NotNull] PgpSignature signature) { var key = PublicBundle.GetPublicKey(signature.KeyId); if (key == null) { return(new MissingKeySignature(signature.KeyId)); } else { signature.InitVerify(key); signature.Update(data); if (signature.Verify()) { return(new ValidSignature(key.KeyId, key.GetFingerprint(), signature.CreationTime)); } else { var badSig = new BadSignature(signature.KeyId); Log.Warn(badSig.ToString()); return(badSig); } } }
private OpenPgpSignature Verify(ArraySegment <byte> data, PgpSignature signature) { var key = PublicBundle.GetPublicKey(signature.KeyId); if (key == null) { return(new MissingKeySignature(signature.KeyId)); } else { signature.InitVerify(key); signature.Update(data.Array, data.Offset, data.Count); if (signature.Verify()) { return(new ValidSignature(key.KeyId, key.GetFingerprint(), signature.CreationTime)); } else { var badSig = new BadSignature(signature.KeyId); Log.Warn(badSig.ToString()); return(badSig); } } }
/// <inheritdoc/> public string ExportKey(IKeyIDContainer keyIDContainer) { #region Sanity checks if (keyIDContainer == null) { throw new ArgumentNullException(nameof(keyIDContainer)); } #endregion var publicKey = ((SecretBundle.GetSecretKey(keyIDContainer.KeyID) != null) ? SecretBundle.GetSecretKey(keyIDContainer.KeyID).PublicKey : null) ?? PublicBundle.GetPublicKey(keyIDContainer.KeyID); if (publicKey == null) { throw new KeyNotFoundException("Specified OpenPGP key not found on system"); } var output = new MemoryStream(); using (var armored = new ArmoredOutputStream(output)) publicKey.Encode(armored); return(output.ReadToString(Encoding.ASCII).Replace(Environment.NewLine, "\n")); }