internal static void ReadUserIDs( BcpgInputStream bcpgInput, out IList ids, out IList idTrusts, out IList idSigs) { ids = Platform.CreateArrayList(); idTrusts = Platform.CreateArrayList(); idSigs = Platform.CreateArrayList(); while (bcpgInput.NextPacketTag() == PacketTag.UserId || bcpgInput.NextPacketTag() == PacketTag.UserAttribute) { Packet obj = bcpgInput.ReadPacket(); if (obj is UserIdPacket) { UserIdPacket id = (UserIdPacket)obj; ids.Add(id.GetId()); } else { UserAttributePacket user = (UserAttributePacket) obj; ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets())); } idTrusts.Add( ReadOptionalTrustPacket(bcpgInput)); idSigs.Add( ReadSignaturesAndTrust(bcpgInput)); } }
internal static void ReadUserIDs(BcpgInputStream bcpgInput, out IList ids, out IList<ITrustPacket> idTrusts, out IList<IList<IPgpSignature>> idSigs) { ids = Platform.CreateArrayList(); idTrusts = Platform.CreateArrayList<ITrustPacket>(); idSigs = Platform.CreateArrayList<IList<IPgpSignature>>(); while (bcpgInput.NextPacketTag() == PacketTag.UserId || bcpgInput.NextPacketTag() == PacketTag.UserAttribute) { var obj = bcpgInput.ReadPacket(); var userIdPacket = obj as UserIdPacket; if (userIdPacket != null) { ids.Add(userIdPacket.GetId()); } else { var user = (UserAttributePacket)obj; ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets())); } idTrusts.Add(ReadOptionalTrustPacket(bcpgInput)); idSigs.Add(ReadSignaturesAndTrust(bcpgInput)); } }
internal static TrustPacket ReadOptionalTrustPacket( BcpgInputStream bcpgInput) { return (bcpgInput.NextPacketTag() == PacketTag.Trust) ? (TrustPacket) bcpgInput.ReadPacket() : null; }
internal ExperimentalPacket( PacketTag tag, BcpgInputStream bcpgIn) { _tag = tag; _contents = bcpgIn.ReadAll(); }
internal static void ReadUserIDs( BcpgInputStream bcpgInput, out IList ids, out IList idTrusts, out IList idSigs) { ids = Platform.CreateArrayList(); idTrusts = Platform.CreateArrayList(); idSigs = Platform.CreateArrayList(); // EDDINGTON try { while (bcpgInput.NextPacketTag() == PacketTag.UserId || bcpgInput.NextPacketTag() == PacketTag.UserAttribute) { Packet obj = bcpgInput.ReadPacket(); if (obj is UserIdPacket) { UserIdPacket id = (UserIdPacket)obj; ids.Add(id.GetId()); } else { UserAttributePacket user = (UserAttributePacket) obj; ids.Add(new PgpUserAttributeSubpacketVector(user.GetSubpackets())); } idTrusts.Add( ReadOptionalTrustPacket(bcpgInput)); idSigs.Add( ReadSignaturesAndTrust(bcpgInput)); } } catch (Exception ex) { // EDDINGTON logger.Debug("ReadUserIDs: Exception occured: {0}", ex.Message); foreach (var id in ids) { var sid = id.ToString(); if (id is UserIdPacket) sid = ((UserIdPacket)id).GetId(); logger.Debug("ReadUserIDs: ID: {0}", sid); } throw; } }
internal static IList<IPgpSignature> ReadSignaturesAndTrust(BcpgInputStream bcpgInput) { try { var sigList = Platform.CreateArrayList<IPgpSignature>(); while (bcpgInput.NextPacketTag() == PacketTag.Signature) { var signaturePacket = (SignaturePacket)bcpgInput.ReadPacket(); var trustPacket = ReadOptionalTrustPacket(bcpgInput); sigList.Add(new PgpSignature(signaturePacket, trustPacket)); } return sigList; } catch (PgpException e) { throw new IOException("can't create signature object: " + e.Message, e); } }
public PgpEncryptedDataList( BcpgInputStream bcpgInput) { while (bcpgInput.NextPacketTag() == PacketTag.PublicKeyEncryptedSession || bcpgInput.NextPacketTag() == PacketTag.SymmetricKeyEncryptedSessionKey) { list.Add(bcpgInput.ReadPacket()); } data = (InputStreamPacket)bcpgInput.ReadPacket(); for (int i = 0; i != list.Count; i++) { if (list[i] is SymmetricKeyEncSessionPacket) { list[i] = new PgpPbeEncryptedData((SymmetricKeyEncSessionPacket) list[i], data); } else { list[i] = new PgpPublicKeyEncryptedData((PublicKeyEncSessionPacket) list[i], data); } } }
internal static PgpPublicKey ReadSubkey(BcpgInputStream bcpgInput) { PublicKeyPacket pk = (PublicKeyPacket) bcpgInput.ReadPacket(); TrustPacket kTrust = ReadOptionalTrustPacket(bcpgInput); // PGP 8 actually leaves out the signature. IList sigList = ReadSignaturesAndTrust(bcpgInput); return new PgpPublicKey(pk, kTrust, sigList); }
public PgpExperimental( BcpgInputStream bcpgIn) { p = (ExperimentalPacket) bcpgIn.ReadPacket(); }
public Stream GetDataStream(PgpPrivateKey privKey) { byte[] array = RecoverSessionData(privKey); if (!ConfirmCheckSum(array)) { throw new PgpKeyValidationException("key checksum failed"); } SymmetricKeyAlgorithmTag symmetricKeyAlgorithmTag = (SymmetricKeyAlgorithmTag)array[0]; if (symmetricKeyAlgorithmTag == SymmetricKeyAlgorithmTag.Null) { return(encData.GetInputStream()); } string symmetricCipherName = PgpUtilities.GetSymmetricCipherName(symmetricKeyAlgorithmTag); string str = symmetricCipherName; IBufferedCipher cipher; try { str = ((!(encData is SymmetricEncIntegrityPacket)) ? (str + "/OpenPGPCFB/NoPadding") : (str + "/CFB/NoPadding")); cipher = CipherUtilities.GetCipher(str); } catch (PgpException ex) { throw ex; } catch (Exception exception) { throw new PgpException("exception creating cipher", exception); } try { KeyParameter parameters = ParameterUtilities.CreateKeyParameter(symmetricCipherName, array, 1, array.Length - 3); byte[] array2 = new byte[cipher.GetBlockSize()]; cipher.Init(forEncryption: false, new ParametersWithIV(parameters, array2)); encStream = BcpgInputStream.Wrap(new CipherStream(encData.GetInputStream(), cipher, null)); if (encData is SymmetricEncIntegrityPacket) { truncStream = new TruncatedStream(encStream); string digestName = PgpUtilities.GetDigestName(HashAlgorithmTag.Sha1); IDigest digest = DigestUtilities.GetDigest(digestName); encStream = new DigestStream(truncStream, digest, null); } if (Streams.ReadFully(encStream, array2, 0, array2.Length) < array2.Length) { throw new EndOfStreamException("unexpected end of stream."); } int num = encStream.ReadByte(); int num2 = encStream.ReadByte(); if (num < 0 || num2 < 0) { throw new EndOfStreamException("unexpected end of stream."); } return(encStream); } catch (PgpException ex2) { throw ex2; } catch (Exception exception2) { throw new PgpException("Exception starting decryption", exception2); } }
internal SymmetricEncIntegrityPacket(BcpgInputStream bcpgIn) : base(bcpgIn) { this.Version = bcpgIn.ReadByte(); }
internal PgpSignature( BcpgInputStream bcpgInput) : this((SignaturePacket)bcpgInput.ReadPacket()) { }
/// <summary>Extract a <c>PgpPrivateKey</c> from this secret key's encrypted contents.</summary> public PgpPrivateKey ExtractPrivateKey( char[] passPhrase) { if (secret.GetSecretKeyData() == null) { return(null); } PublicKeyPacket pubPk = secret.PublicKeyPacket; try { byte[] data = ExtractKeyData(passPhrase); BcpgInputStream bcpgIn = BcpgInputStream.Wrap(new MemoryStream(data, false)); AsymmetricKeyParameter privateKey; switch (pubPk.Algorithm) { case PublicKeyAlgorithmTag.RsaEncrypt: case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaSign: RsaPublicBcpgKey rsaPub = (RsaPublicBcpgKey)pubPk.Key; RsaSecretBcpgKey rsaPriv = new RsaSecretBcpgKey(bcpgIn); RsaPrivateCrtKeyParameters rsaPrivSpec = new RsaPrivateCrtKeyParameters( rsaPriv.Modulus, rsaPub.PublicExponent, rsaPriv.PrivateExponent, rsaPriv.PrimeP, rsaPriv.PrimeQ, rsaPriv.PrimeExponentP, rsaPriv.PrimeExponentQ, rsaPriv.CrtCoefficient); privateKey = rsaPrivSpec; break; case PublicKeyAlgorithmTag.Dsa: DsaPublicBcpgKey dsaPub = (DsaPublicBcpgKey)pubPk.Key; DsaSecretBcpgKey dsaPriv = new DsaSecretBcpgKey(bcpgIn); DsaParameters dsaParams = new DsaParameters(dsaPub.P, dsaPub.Q, dsaPub.G); privateKey = new DsaPrivateKeyParameters(dsaPriv.X, dsaParams); break; case PublicKeyAlgorithmTag.ElGamalEncrypt: case PublicKeyAlgorithmTag.ElGamalGeneral: ElGamalPublicBcpgKey elPub = (ElGamalPublicBcpgKey)pubPk.Key; ElGamalSecretBcpgKey elPriv = new ElGamalSecretBcpgKey(bcpgIn); ElGamalParameters elParams = new ElGamalParameters(elPub.P, elPub.G); privateKey = new ElGamalPrivateKeyParameters(elPriv.X, elParams); break; default: throw new PgpException("unknown public key algorithm encountered"); } return(new PgpPrivateKey(privateKey, this.KeyId)); } catch (PgpException e) { throw e; } catch (Exception e) { throw new PgpException("Exception constructing key", e); } }
internal SignaturePacket(BcpgInputStream bcpgIn) { version = bcpgIn.ReadByte(); if (version == 3 || version == 2) { bcpgIn.ReadByte(); signatureType = bcpgIn.ReadByte(); creationTime = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000; keyId |= (long)bcpgIn.ReadByte() << 56; keyId |= (long)bcpgIn.ReadByte() << 48; keyId |= (long)bcpgIn.ReadByte() << 40; keyId |= (long)bcpgIn.ReadByte() << 32; keyId |= (long)bcpgIn.ReadByte() << 24; keyId |= (long)bcpgIn.ReadByte() << 16; keyId |= (long)bcpgIn.ReadByte() << 8; keyId |= (uint)bcpgIn.ReadByte(); keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte(); } else { if (version != 4) { throw new Exception("unsupported version: " + version); } signatureType = bcpgIn.ReadByte(); keyAlgorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte(); hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte(); int num = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); byte[] buffer = new byte[num]; bcpgIn.ReadFully(buffer); SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer, writable: false)); IList list = Platform.CreateArrayList(); SignatureSubpacket value; while ((value = signatureSubpacketsParser.ReadPacket()) != null) { list.Add(value); } hashedData = new SignatureSubpacket[list.Count]; for (int i = 0; i != hashedData.Length; i++) { SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[i]; if (signatureSubpacket is IssuerKeyId) { keyId = ((IssuerKeyId)signatureSubpacket).KeyId; } else if (signatureSubpacket is SignatureCreationTime) { creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime()); } hashedData[i] = signatureSubpacket; } int num2 = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte(); byte[] buffer2 = new byte[num2]; bcpgIn.ReadFully(buffer2); signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, writable: false)); list.Clear(); while ((value = signatureSubpacketsParser.ReadPacket()) != null) { list.Add(value); } unhashedData = new SignatureSubpacket[list.Count]; for (int j = 0; j != unhashedData.Length; j++) { SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[j]; if (signatureSubpacket2 is IssuerKeyId) { keyId = ((IssuerKeyId)signatureSubpacket2).KeyId; } unhashedData[j] = signatureSubpacket2; } } fingerprint = new byte[2]; bcpgIn.ReadFully(fingerprint); switch (keyAlgorithm) { case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaSign: { MPInteger mPInteger8 = new MPInteger(bcpgIn); signature = new MPInteger[1] { mPInteger8 }; return; } case PublicKeyAlgorithmTag.Dsa: { MPInteger mPInteger6 = new MPInteger(bcpgIn); MPInteger mPInteger7 = new MPInteger(bcpgIn); signature = new MPInteger[2] { mPInteger6, mPInteger7 }; return; } case PublicKeyAlgorithmTag.ElGamalEncrypt: case PublicKeyAlgorithmTag.ElGamalGeneral: { MPInteger mPInteger3 = new MPInteger(bcpgIn); MPInteger mPInteger4 = new MPInteger(bcpgIn); MPInteger mPInteger5 = new MPInteger(bcpgIn); signature = new MPInteger[3] { mPInteger3, mPInteger4, mPInteger5 }; return; } case PublicKeyAlgorithmTag.ECDsa: { MPInteger mPInteger = new MPInteger(bcpgIn); MPInteger mPInteger2 = new MPInteger(bcpgIn); signature = new MPInteger[2] { mPInteger, mPInteger2 }; return; } } if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11) { signature = null; MemoryStream memoryStream = new MemoryStream(); int num3; while ((num3 = bcpgIn.ReadByte()) >= 0) { memoryStream.WriteByte((byte)num3); } signatureEncoding = memoryStream.ToArray(); return; } throw new IOException("unknown signature key algorithm: " + keyAlgorithm); }
public InputStreamPacket( BcpgInputStream bcpgIn) { this.bcpgIn = bcpgIn; }
internal SecretSubkeyPacket( BcpgInputStream bcpgIn) : base(bcpgIn) { }
protected ECPublicBcpgKey(BcpgInputStream bcpgIn) { oid = DerObjectIdentifier.GetInstance(Asn1Object.FromByteArray(ReadBytesOfEncodedLength(bcpgIn))); point = new MPInteger(bcpgIn).Value; }
public InputStreamPacket(BcpgInputStream bcpgIn) { _bcpgIn = bcpgIn; }
internal PgpPrivateKey DoExtractPrivateKey(byte[] rawPassPhrase, bool clearPassPhrase) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown if (IsPrivateKeyEmpty) { return(null); } PublicKeyPacket publicKeyPacket = secret.PublicKeyPacket; try { byte[] array = ExtractKeyData(rawPassPhrase, clearPassPhrase); BcpgInputStream bcpgIn = BcpgInputStream.Wrap((Stream) new MemoryStream(array, false)); AsymmetricKeyParameter privateKey; switch (publicKeyPacket.Algorithm) { case PublicKeyAlgorithmTag.RsaGeneral: case PublicKeyAlgorithmTag.RsaEncrypt: case PublicKeyAlgorithmTag.RsaSign: { RsaPublicBcpgKey rsaPublicBcpgKey = (RsaPublicBcpgKey)publicKeyPacket.Key; RsaSecretBcpgKey rsaSecretBcpgKey = new RsaSecretBcpgKey(bcpgIn); RsaPrivateCrtKeyParameters rsaPrivateCrtKeyParameters = new RsaPrivateCrtKeyParameters(rsaSecretBcpgKey.Modulus, rsaPublicBcpgKey.PublicExponent, rsaSecretBcpgKey.PrivateExponent, rsaSecretBcpgKey.PrimeP, rsaSecretBcpgKey.PrimeQ, rsaSecretBcpgKey.PrimeExponentP, rsaSecretBcpgKey.PrimeExponentQ, rsaSecretBcpgKey.CrtCoefficient); privateKey = rsaPrivateCrtKeyParameters; break; } case PublicKeyAlgorithmTag.Dsa: { DsaPublicBcpgKey dsaPublicBcpgKey = (DsaPublicBcpgKey)publicKeyPacket.Key; DsaSecretBcpgKey dsaSecretBcpgKey = new DsaSecretBcpgKey(bcpgIn); DsaParameters parameters2 = new DsaParameters(dsaPublicBcpgKey.P, dsaPublicBcpgKey.Q, dsaPublicBcpgKey.G); privateKey = new DsaPrivateKeyParameters(dsaSecretBcpgKey.X, parameters2); break; } case PublicKeyAlgorithmTag.EC: privateKey = GetECKey("ECDH", bcpgIn); break; case PublicKeyAlgorithmTag.ECDsa: privateKey = GetECKey("ECDSA", bcpgIn); break; case PublicKeyAlgorithmTag.ElGamalEncrypt: case PublicKeyAlgorithmTag.ElGamalGeneral: { ElGamalPublicBcpgKey elGamalPublicBcpgKey = (ElGamalPublicBcpgKey)publicKeyPacket.Key; ElGamalSecretBcpgKey elGamalSecretBcpgKey = new ElGamalSecretBcpgKey(bcpgIn); ElGamalParameters parameters = new ElGamalParameters(elGamalPublicBcpgKey.P, elGamalPublicBcpgKey.G); privateKey = new ElGamalPrivateKeyParameters(elGamalSecretBcpgKey.X, parameters); break; } default: throw new PgpException("unknown public key algorithm encountered"); } return(new PgpPrivateKey(KeyId, publicKeyPacket, privateKey)); } catch (PgpException ex) { throw ex; } catch (global::System.Exception exception) { throw new PgpException("Exception constructing key", exception); } }
internal PgpOnePassSignature( BcpgInputStream pIn) : this((OnePassSignaturePacket)pIn.ReadPacket()) { }
public PgpExperimental( BcpgInputStream bcpgIn) { p = (ExperimentalPacket)bcpgIn.ReadPacket(); }
public PgpCompressedData( BcpgInputStream bcpgInput) { data = (CompressedDataPacket)bcpgInput.ReadPacket(); }
public PgpMarker( BcpgInputStream bcpgIn) { p = (MarkerPacket) bcpgIn.ReadPacket(); }
/// <summary>Return the decrypted input stream, using the passed in passphrase.</summary> public Stream GetDataStream( char[] passPhrase) { try { SymmetricKeyAlgorithmTag keyAlgorithm = keyData.EncAlgorithm; KeyParameter key = PgpUtilities.MakeKeyFromPassPhrase( keyAlgorithm, keyData.S2k, passPhrase); byte[] secKeyData = keyData.GetSecKeyData(); if (secKeyData != null && secKeyData.Length > 0) { IBufferedCipher keyCipher = CipherUtilities.GetCipher( PgpUtilities.GetSymmetricCipherName(keyAlgorithm) + "/CFB/NoPadding"); keyCipher.Init(false, new ParametersWithIV(key, new byte[keyCipher.GetBlockSize()])); byte[] keyBytes = keyCipher.DoFinal(secKeyData); keyAlgorithm = (SymmetricKeyAlgorithmTag)keyBytes[0]; key = ParameterUtilities.CreateKeyParameter( PgpUtilities.GetSymmetricCipherName(keyAlgorithm), keyBytes, 1, keyBytes.Length - 1); } IBufferedCipher c = CreateStreamCipher(keyAlgorithm); byte[] iv = new byte[c.GetBlockSize()]; c.Init(false, new ParametersWithIV(key, iv)); encStream = BcpgInputStream.Wrap(new CipherStream(encData.GetInputStream(), c, null)); if (encData is SymmetricEncIntegrityPacket) { truncStream = new TruncatedStream(encStream); string digestName = PgpUtilities.GetDigestName(HashAlgorithmTag.Sha1); IDigest digest = DigestUtilities.GetDigest(digestName); encStream = new DigestStream(truncStream, digest, null); } if (Streams.ReadFully(encStream, iv, 0, iv.Length) < iv.Length) { throw new EndOfStreamException("unexpected end of stream."); } int v1 = encStream.ReadByte(); int v2 = encStream.ReadByte(); if (v1 < 0 || v2 < 0) { throw new EndOfStreamException("unexpected end of stream."); } // Note: the oracle attack on the "quick check" bytes is not deemed // a security risk for PBE (see PgpPublicKeyEncryptedData) bool repeatCheckPassed = iv[iv.Length - 2] == (byte)v1 && iv[iv.Length - 1] == (byte)v2; // Note: some versions of PGP appear to produce 0 for the extra // bytes rather than repeating the two previous bytes bool zeroesCheckPassed = v1 == 0 && v2 == 0; if (!repeatCheckPassed && !zeroesCheckPassed) { throw new PgpDataValidationException("quick check failed."); } return(encStream); } catch (PgpException e) { throw e; } catch (Exception e) { throw new PgpException("Exception creating cipher", e); } }
/// <summary> /// Initializes a new instance of the <see cref="SecretSubkeyPacket"/> class. /// </summary> /// <param name="bcpgIn">The BCPG in.</param> internal SecretSubkeyPacket(BcpgInputStream bcpgIn) : base(bcpgIn) { }
/// <summary>Return the decrypted data stream for the packet.</summary> public Stream GetDataStream( PgpPrivateKey privKey) { byte[] sessionData = RecoverSessionData(privKey); if (!ConfirmCheckSum(sessionData)) { throw new PgpKeyValidationException("key checksum failed"); } SymmetricKeyAlgorithmTag symmAlg = (SymmetricKeyAlgorithmTag)sessionData[0]; if (symmAlg == SymmetricKeyAlgorithmTag.Null) { return(encData.GetInputStream()); } IBufferedCipher cipher; string cipherName = PgpUtilities.GetSymmetricCipherName(symmAlg); string cName = cipherName; try { if (encData is SymmetricEncIntegrityPacket) { cName += "/CFB/NoPadding"; } else { cName += "/OpenPGPCFB/NoPadding"; } cipher = CipherUtilities.GetCipher(cName); } catch (PgpException e) { throw e; } catch (Exception e) { throw new PgpException("exception creating cipher", e); } try { KeyParameter key = ParameterUtilities.CreateKeyParameter( cipherName, sessionData, 1, sessionData.Length - 3); byte[] iv = new byte[cipher.GetBlockSize()]; cipher.Init(false, new ParametersWithIV(key, iv)); encStream = BcpgInputStream.Wrap(new CipherStream(encData.GetInputStream(), cipher, null)); if (encData is SymmetricEncIntegrityPacket) { truncStream = new TruncatedStream(encStream); string digestName = PgpUtilities.GetDigestName(HashAlgorithmTag.Sha1); IDigest digest = DigestUtilities.GetDigest(digestName); encStream = new DigestStream(truncStream, digest, null); } if (Streams.ReadFully(encStream, iv, 0, iv.Length) < iv.Length) { throw new EndOfStreamException("unexpected end of stream."); } int v1 = encStream.ReadByte(); int v2 = encStream.ReadByte(); if (v1 < 0 || v2 < 0) { throw new EndOfStreamException("unexpected end of stream."); } // Note: the oracle attack on the "quick check" bytes is deemed // a security risk for typical public key encryption usages, // therefore we do not perform the check. // bool repeatCheckPassed = // iv[iv.Length - 2] == (byte)v1 // && iv[iv.Length - 1] == (byte)v2; // // // Note: some versions of PGP appear to produce 0 for the extra // // bytes rather than repeating the two previous bytes // bool zeroesCheckPassed = // v1 == 0 // && v2 == 0; // // if (!repeatCheckPassed && !zeroesCheckPassed) // { // throw new PgpDataValidationException("quick check failed."); // } return(encStream); } catch (PgpException e) { throw e; } catch (Exception e) { throw new PgpException("Exception starting decryption", e); } }
internal CompressedDataPacket( BcpgInputStream bcpgIn) : base(bcpgIn) { this.algorithm = (CompressionAlgorithmTag)bcpgIn.ReadByte(); }
public UserIdPacket(BcpgInputStream bcpgIn) { idData = bcpgIn.ReadAll(); }
private ECPrivateKeyParameters GetECKey(string algorithm, BcpgInputStream bcpgIn) { ECPublicBcpgKey ecdsaPub = (ECPublicBcpgKey)secret.PublicKeyPacket.Key; ECSecretBcpgKey ecdsaPriv = new ECSecretBcpgKey(bcpgIn); return new ECPrivateKeyParameters(algorithm, ecdsaPriv.X, ecdsaPub.CurveOid); }
public PgpSecretKeyRing( Stream inputStream) { this.keys = Platform.CreateArrayList(); this.extraPubKeys = Platform.CreateArrayList(); BcpgInputStream bcpgInput = BcpgInputStream.Wrap(inputStream); PacketTag initialTag = bcpgInput.NextPacketTag(); if (initialTag != PacketTag.SecretKey && initialTag != PacketTag.SecretSubkey) { throw new IOException("secret key ring doesn't start with secret key tag: " + "tag 0x" + ((int)initialTag).ToString("X")); } SecretKeyPacket secret = (SecretKeyPacket)bcpgInput.ReadPacket(); // // ignore GPG comment packets if found. // while (bcpgInput.NextPacketTag() == PacketTag.Experimental2) { bcpgInput.ReadPacket(); } TrustPacket trust = ReadOptionalTrustPacket(bcpgInput); // revocation and direct signatures IList keySigs = ReadSignaturesAndTrust(bcpgInput); IList ids, idTrusts, idSigs; ReadUserIDs(bcpgInput, out ids, out idTrusts, out idSigs); keys.Add(new PgpSecretKey(secret, new PgpPublicKey(secret.PublicKeyPacket, trust, keySigs, ids, idTrusts, idSigs))); // Read subkeys while (bcpgInput.NextPacketTag() == PacketTag.SecretSubkey || bcpgInput.NextPacketTag() == PacketTag.PublicSubkey) { if (bcpgInput.NextPacketTag() == PacketTag.SecretSubkey) { SecretSubkeyPacket sub = (SecretSubkeyPacket)bcpgInput.ReadPacket(); // // ignore GPG comment packets if found. // while (bcpgInput.NextPacketTag() == PacketTag.Experimental2) { bcpgInput.ReadPacket(); } TrustPacket subTrust = ReadOptionalTrustPacket(bcpgInput); IList sigList = ReadSignaturesAndTrust(bcpgInput); keys.Add(new PgpSecretKey(sub, new PgpPublicKey(sub.PublicKeyPacket, subTrust, sigList))); } else { PublicSubkeyPacket sub = (PublicSubkeyPacket)bcpgInput.ReadPacket(); TrustPacket subTrust = ReadOptionalTrustPacket(bcpgInput); IList sigList = ReadSignaturesAndTrust(bcpgInput); extraPubKeys.Add(new PgpPublicKey(sub, subTrust, sigList)); } } }
public PgpObjectFactory( Stream inputStream) { this.bcpgIn = BcpgInputStream.Wrap(inputStream); }
private byte lastb; // Initial value anything but '\r' internal PgpSignature( BcpgInputStream bcpgInput) : this((SignaturePacket)bcpgInput.ReadPacket()) { }
public PgpCompressedData( BcpgInputStream bcpgInput) { data = (CompressedDataPacket) bcpgInput.ReadPacket(); }
public RsaPublicBcpgKey(BcpgInputStream bcpgIn) { n = new MPInteger(bcpgIn); e = new MPInteger(bcpgIn); }
public PgpLiteralData( BcpgInputStream bcpgInput) { data = (LiteralDataPacket)bcpgInput.ReadPacket(); }
public PgpLiteralData( BcpgInputStream bcpgInput) { data = (LiteralDataPacket) bcpgInput.ReadPacket(); }
protected internal ECDsaPublicBcpgKey(BcpgInputStream bcpgIn) : base(bcpgIn) { }