/// <summary> /// Create a PgpPublicKey from the passed in lightweight one. /// </summary> /// <remarks> /// Note: the time passed in affects the value of the key's keyId, so you probably only want /// to do this once for a lightweight key, or make sure you keep track of the time you used. /// </remarks> /// <param name="algorithm">Asymmetric algorithm type representing the public key.</param> /// <param name="pubKey">Actual public key to associate.</param> /// <param name="time">Date of creation.</param> /// <exception cref="ArgumentException">If <c>pubKey</c> is not public.</exception> /// <exception cref="PgpException">On key creation problem.</exception> public PgpPublicKey(PublicKeyAlgorithmTag algorithm, IAsymmetricKeyParameter pubKey, DateTime time) { if (pubKey.IsPrivate) { throw new ArgumentException(@"Expected a public key", "pubKey"); } IBcpgPublicKey bcpgKey; if (pubKey is RsaKeyParameters) { var rK = (RsaKeyParameters)pubKey; bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent); } else if (pubKey is DsaPublicKeyParameters) { var dK = (DsaPublicKeyParameters)pubKey; var dP = dK.Parameters; bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y); } else if (pubKey is ElGamalPublicKeyParameters) { var eK = (ElGamalPublicKeyParameters)pubKey; var eS = eK.Parameters; bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y); } else if (pubKey is ECDHPublicKeyParameters) { var ecdh = (ECDHPublicKeyParameters)pubKey; bcpgKey = new ECDHPublicBcpgKey(ecdh.Q, ecdh.PublicKeyParamSet, ecdh.HashAlgorithm, ecdh.SymmetricKeyAlgorithm); } else if (pubKey is ECPublicKeyParameters) { var ecdsa = (ECPublicKeyParameters)pubKey; bcpgKey = new ECDSAPublicBcpgKey(ecdsa.Q, ecdsa.PublicKeyParamSet); } else { throw new PgpException("unknown key class"); } _publicPk = new PublicKeyPacket(algorithm, time, bcpgKey); _ids = Platform.CreateArrayList(); _idSigs = Platform.CreateArrayList <IList <IPgpSignature> >(); try { Init(); } catch (IOException e) { throw new PgpException("exception calculating keyId", e); } }
/// <summary> /// Create a PgpPublicKey from the passed in lightweight one. /// </summary> /// <remarks> /// Note: the time passed in affects the value of the key's keyId, so you probably only want /// to do this once for a lightweight key, or make sure you keep track of the time you used. /// </remarks> /// <param name="algorithm">Asymmetric algorithm type representing the public key.</param> /// <param name="pubKey">Actual public key to associate.</param> /// <param name="time">Date of creation.</param> /// <exception cref="ArgumentException">If <c>pubKey</c> is not public.</exception> /// <exception cref="PgpException">On key creation problem.</exception> public PgpPublicKey(PublicKeyAlgorithmTag algorithm, IAsymmetricKeyParameter pubKey, DateTime time) { if (pubKey.IsPrivate) throw new ArgumentException(@"Expected a public key", "pubKey"); IBcpgPublicKey bcpgKey; if (pubKey is RsaKeyParameters) { var rK = (RsaKeyParameters)pubKey; bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent); } else if (pubKey is DsaPublicKeyParameters) { var dK = (DsaPublicKeyParameters)pubKey; var dP = dK.Parameters; bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y); } else if (pubKey is ElGamalPublicKeyParameters) { var eK = (ElGamalPublicKeyParameters)pubKey; var eS = eK.Parameters; bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y); } else if (pubKey is ECDHPublicKeyParameters) { var ecdh = (ECDHPublicKeyParameters)pubKey; bcpgKey = new ECDHPublicBcpgKey(ecdh.Q, ecdh.PublicKeyParamSet, ecdh.HashAlgorithm, ecdh.SymmetricKeyAlgorithm); } else if (pubKey is ECPublicKeyParameters) { var ecdsa = (ECPublicKeyParameters)pubKey; bcpgKey = new ECDSAPublicBcpgKey(ecdsa.Q, ecdsa.PublicKeyParamSet); } else { throw new PgpException("unknown key class"); } _publicPk = new PublicKeyPacket(algorithm, time, bcpgKey); _ids = Platform.CreateArrayList(); _idSigs = Platform.CreateArrayList<IList<IPgpSignature>>(); try { Init(); } catch (IOException e) { throw new PgpException("exception calculating keyId", e); } }