本文整理汇总了C#中Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey类的典型用法代码示例。如果您正苦于以下问题:C# PgpPublicKey类的具体用法?C# PgpPublicKey怎么用?C# PgpPublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PgpPublicKey类属于Org.BouncyCastle.Bcpg.OpenPgp命名空间,在下文中一共展示了PgpPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenPgpDigitalCertificate
internal OpenPgpDigitalCertificate (PgpPublicKey pubkey)
{
var data = pubkey.GetFingerprint ();
var builder = new StringBuilder ();
for (int i = 0; i < data.Length; i++)
builder.Append (data[i].ToString ("X"));
// var trust = pubkey.GetTrustData ();
// if (trust != null) {
// TrustLevel = (TrustLevel) (trust[0] & 15);
// } else {
// TrustLevel = TrustLevel.None;
// }
Fingerprint = builder.ToString ();
PublicKey = pubkey;
foreach (string userId in pubkey.GetUserIds ()) {
data = Encoding.UTF8.GetBytes (userId);
MailboxAddress mailbox;
int index = 0;
if (!MailboxAddress.TryParse (ParserOptions.Default, data, ref index, data.Length, false, out mailbox))
continue;
Email = mailbox.Address;
Name = mailbox.Name;
break;
}
}
示例2: PgpKeyPair
/// <summary>Create a key pair from a PgpPrivateKey and a PgpPublicKey.</summary>
/// <param name="pub">The public key.</param>
/// <param name="priv">The private key.</param>
public PgpKeyPair(
PgpPublicKey pub,
PgpPrivateKey priv)
{
this.pub = pub;
this.priv = priv;
}
示例3: InsertPublicKey
/// <summary>
/// Returns a new key ring with the public key passed in either added or
/// replacing an existing one.
/// </summary>
/// <param name="pubRing">The public key ring to be modified.</param>
/// <param name="pubKey">The public key to be inserted.</param>
/// <returns>A new <c>PgpPublicKeyRing</c></returns>
public static PgpPublicKeyRing InsertPublicKey(
PgpPublicKeyRing pubRing,
PgpPublicKey pubKey)
{
ArrayList keys = new ArrayList(pubRing.keys);
bool found = false;
for (int i = 0; i != keys.Count; i++)
{
PgpPublicKey key = (PgpPublicKey) keys[i];
if (key.KeyId == pubKey.KeyId)
{
found = true;
keys[i] = pubKey;
}
}
if (!found)
{
keys.Add(pubKey);
}
return new PgpPublicKeyRing(keys);
}
示例4: PgpSecretKey
internal PgpSecretKey(
SecretKeyPacket secret,
PgpPublicKey pub)
{
this.secret = secret;
this.pub = pub;
}
示例5: PgpKeyPair
public PgpKeyPair(
PublicKeyAlgorithmTag algorithm,
AsymmetricKeyParameter pubKey,
AsymmetricKeyParameter privKey,
DateTime time)
{
this.pub = new PgpPublicKey(algorithm, pubKey, time);
this.priv = new PgpPrivateKey(privKey, pub.KeyId);
}
示例6: PgpSecretKey
internal PgpSecretKey(
PgpPrivateKey privKey,
PgpPublicKey pubKey,
SymmetricKeyAlgorithmTag encAlgorithm,
char[] passPhrase,
bool useSha1,
SecureRandom rand)
: this(privKey, pubKey, encAlgorithm, passPhrase, useSha1, rand, false)
{
}
示例7: Load
private void Load(PgpPublicKey key)
{
this.KeyId = key.KeyId.ToString("X");
if (this.KeyId != null && this.KeyId.Length >= 15)
{
this.KeyIdShort = this.KeyId.Substring(this.KeyId.Length - 8);
}
this.Algorithm = key.Algorithm.ToString();
this.BitStrength = key.BitStrength;
this.IsMasterKey = key.IsMasterKey;
this.IsEncryptionKey = key.IsEncryptionKey;
this.Version = key.Version;
this.CreatedOnUtc = key.CreationTime.ToUniversalTime();
var validForSeconds = key.GetValidSeconds();
if(validForSeconds > 0)
{
this.Expires = this.CreatedOnUtc.Value.AddSeconds(validForSeconds);
}
//this.ValidDays = key.ValidDays;
//if (this.ValidDays.HasValue)
//{
// this.Expires = this.CreatedOnUtc.Value.AddDays(this.ValidDays.Value);
//}
//else
//{
// this.Expires = null;
//}
try
{
var userIds = key.GetUserIds();
if (userIds != null)
{
var enumerator = userIds.GetEnumerator();
if (enumerator.MoveNext())
{
var userIdentity = enumerator.Current as string;
if (userIdentity != null && userIdentity.Contains("<") && userIdentity.Contains(">"))
{
var name = userIdentity.Substring(0, userIdentity.IndexOf("<") - 1).Trim();
this.IdentityName = name;
var email = userIdentity.Substring(userIdentity.IndexOf("<") + 1);
email = email.Substring(0, email.IndexOf(">")).Trim();
this.IdentityEmail = email;
}
}
}
}
catch { }
}
示例8: IsSigningAlg
public bool IsSigningAlg(PgpPublicKey key)
{
var alg = key.Algorithm;
switch (alg)
{
case PublicKeyAlgorithmTag.Dsa:
case PublicKeyAlgorithmTag.RsaSign:
case PublicKeyAlgorithmTag.ECDsa:
return true;
}
return true;
}
示例9: PgpEncrypt
public static Stream PgpEncrypt(this Stream toEncrypt, PgpPublicKey encryptionKey, bool armor = true, bool verify = false)
{
var outStream = new MemoryStream();
var encryptor = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Cast5, verify, new SecureRandom());
var literalizer = new PgpLiteralDataGenerator();
var compressor = new PgpCompressedDataGenerator(CompressionAlgorithmTag.Zip);
encryptor.AddMethod(encryptionKey);
//it would be nice if these streams were read/write, and supported seeking. Since they are not,
//we need to shunt the data to a read/write stream so that we can control the flow of data as we go.
using (var stream = new MemoryStream()) // this is the read/write stream
using (var armoredStream = armor ? new ArmoredOutputStream(stream) : stream as Stream)
using (var compressedStream = compressor.Open(armoredStream))
{
//data is encrypted first, then compressed, but because of the one-way nature of these streams,
//other "interim" streams are required. The raw data is encapsulated in a "Literal" PGP object.
var rawData = toEncrypt.ReadFully();
var buffer = new byte[1024];
using (var literalOut = new MemoryStream())
using (var literalStream = literalizer.Open(literalOut, PgpLiteralData.Binary, "STREAM", DateTime.UtcNow, buffer))
{
literalStream.Write(rawData, 0, rawData.Length);
literalStream.Close();
var literalData = literalOut.ReadFully();
//The literal data object is then encrypted, which flows into the compressing stream and
//(optionally) into the ASCII armoring stream.
using (var encryptedStream = encryptor.Open(compressedStream, literalData.Length))
{
encryptedStream.Write(literalData, 0, literalData.Length);
encryptedStream.Close();
compressedStream.Close();
armoredStream.Close();
//the stream processes are now complete, and our read/write stream is now populated with
//encrypted data. Convert the stream to a byte array and write to the out stream.
stream.Position = 0;
var data = stream.ReadFully();
outStream.Write(data, 0, data.Length);
}
}
}
outStream.Position = 0;
return outStream;
}
示例10: IsEncryptionAlg
public bool IsEncryptionAlg(PgpPublicKey key)
{
var alg = key.Algorithm;
switch (alg)
{
case PublicKeyAlgorithmTag.DiffieHellman:
case PublicKeyAlgorithmTag.EC:
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.RsaEncrypt:
return true;
}
return false;
}
示例11: PgpSecretKey
public PgpSecretKey(
int certificationLevel,
PgpKeyPair keyPair,
string id,
SymmetricKeyAlgorithmTag encAlgorithm,
char[] passPhrase,
bool useSHA1,
PgpSignatureSubpacketVector hashedPackets,
PgpSignatureSubpacketVector unhashedPackets,
SecureRandom rand)
: this(keyPair, encAlgorithm, passPhrase, useSHA1, rand)
{
try
{
this.trust = null;
this.ids = new ArrayList();
ids.Add(id);
this.idTrusts = new ArrayList();
idTrusts.Add(null);
this.idSigs = new ArrayList();
PgpSignatureGenerator sGen = new PgpSignatureGenerator(
keyPair.PublicKey.Algorithm, HashAlgorithmTag.Sha1);
//
// Generate the certification
//
sGen.InitSign(certificationLevel, keyPair.PrivateKey);
sGen.SetHashedSubpackets(hashedPackets);
sGen.SetUnhashedSubpackets(unhashedPackets);
PgpSignature certification = sGen.GenerateCertification(id, keyPair.PublicKey);
this.pub = PgpPublicKey.AddCertification(keyPair.PublicKey, id, certification);
ArrayList sigList = new ArrayList();
sigList.Add(certification);
idSigs.Add(sigList);
}
catch (PgpException e)
{
throw e;
}
catch (Exception e)
{
throw new PgpException("Exception encrypting key", e);
}
}
示例12: EncryptFile
private static void EncryptFile(Stream outputStream, string fileName, PgpPublicKey encKey, bool armor, bool withIntegrityCheck)
{
if (armor)
outputStream = new ArmoredOutputStream(outputStream);
try
{
MemoryStream bOut = new MemoryStream();
PgpCompressedDataGenerator comData = new PgpCompressedDataGenerator(
CompressionAlgorithmTag.Zip);
PgpUtilities.WriteFileToLiteralData(
comData.Open(bOut),
PgpLiteralData.Binary,
new FileInfo(fileName));
comData.Close();
PgpEncryptedDataGenerator cPk = new PgpEncryptedDataGenerator(
SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck, new SecureRandom());
cPk.AddMethod(encKey);
byte[] bytes = bOut.ToArray();
Stream cOut = cPk.Open(outputStream, bytes.Length);
cOut.Write(bytes, 0, bytes.Length);
cOut.Close();
if (armor)
outputStream.Close();
}
catch (PgpException e)
{
Console.Error.WriteLine(e);
Exception underlyingException = e.InnerException;
if (underlyingException != null)
{
Console.Error.WriteLine(underlyingException.Message);
Console.Error.WriteLine(underlyingException.StackTrace);
}
}
}
示例13: InitVerify
/// <summary>Initialise the signature object for verification.</summary>
public void InitVerify(
PgpPublicKey pubKey)
{
lastb = 0;
try
{
sig = SignerUtilities.GetSigner(
PgpUtilities.GetSignatureName(sigPack.KeyAlgorithm, sigPack.HashAlgorithm));
}
catch (Exception e)
{
throw new PgpException("can't set up signature object.", e);
}
try
{
sig.Init(false, pubKey.GetKey());
}
catch (InvalidKeyException e)
{
throw new PgpException("invalid key.", e);
}
}
示例14: UpdateWithPublicKey
private void UpdateWithPublicKey(
PgpPublicKey key)
{
byte[] keyBytes = GetEncodedPublicKey(key);
this.Update(
(byte) 0x99,
(byte)(keyBytes.Length >> 8),
(byte)(keyBytes.Length));
this.Update(keyBytes);
}
示例15: InitVerify
public void InitVerify(
PgpPublicKey pubKey)
{
lastb = 0;
if (sig == null)
{
GetSig();
}
try
{
sig.Init(false, pubKey.GetKey());
}
catch (InvalidKeyException e)
{
throw new PgpException("invalid key.", e);
}
}