public PgpPublicKey(PgpPacket FromPacket) : base(FromPacket) { PgpPublicKeyUtility KeyUtility; Initialise(); KeyUtility = new PgpPublicKeyUtility(_abRawBytes); _eStatus = KeyUtility.eStatus; if (_eStatus == nStatus.OK) { _Created = KeyUtility.Created; _ePublicKeyAlgorithm = KeyUtility.ePublicKeyAlgorithm; InitialiseKeyParameters(KeyUtility.abModulus, KeyUtility.abExponent); } }
/// <summary></summary> public PgpPrivateKey(PgpPacket FromPacket, EncryptionServices Cryptography) : base(FromPacket) { PgpPublicKeyUtility KeyUtility; Initialise(); _Cryptography = Cryptography; KeyUtility = new PgpPublicKeyUtility(_abRawBytes); // extract the public key bytes _eStatus = KeyUtility.eStatus; if (_eStatus == nStatus.OK) { _PublicKey = new PgpPublicKey(new PgpPacket(KeyUtility.abRawBytes, 0)); // and turn them into a public key _KeyParameters.Exponent = KeyUtility.abExponent; _KeyParameters.Modulus = KeyUtility.abModulus; _eStatus = _PublicKey.eStatus; if (_eStatus == nStatus.OK) { _iOffsetSecretKey = _PublicKey.iHeaderLength + _PublicKey.iDataLength; _eStringToKeyUsage = (nStringToKeyUsage)_abRawBytes[_iOffsetSecretKey++]; if ((_eStringToKeyUsage == nStringToKeyUsage.Sha1) || (_eStringToKeyUsage == nStringToKeyUsage.Checksum)) { _eSymmetricKeyAlgorithm = (nSymmetricKeyAlgorithm)_abRawBytes[_iOffsetSecretKey++]; _eStringToKeySpecifier = (nStringToKeySpecifier)_abRawBytes[_iOffsetSecretKey++]; _eHashAlgorithm = (nHashAlgorithm)_abRawBytes[_iOffsetSecretKey++]; if ((_eSymmetricKeyAlgorithm == nSymmetricKeyAlgorithm.Unencrypted) || (_eSymmetricKeyAlgorithm == nSymmetricKeyAlgorithm.Aes128)) { if (_eStringToKeySpecifier == nStringToKeySpecifier.GnuDummy) { throw new NotImplementedException("eStringToKeySpecifier == nStringToKeySpecifier.GnuDummy"); } } else { _eStatus = nStatus.AlgorithmNotSupported; } } else { _eStatus = nStatus.AlgorithmNotSupported; } } } }
/// <summary></summary> public override void EncodeRawBytes() { PgpPublicKeyUtility KeyUtility = new PgpPublicKeyUtility(_ePacketTag, _Created, _ePublicKeyAlgorithm, _KeyParameters.Modulus, _KeyParameters.Exponent); if (KeyUtility.eStatus == nStatus.OK) { _abRawBytes = KeyUtility.abRawBytes; _iDataLength = KeyUtility.iDataLength; _iHeaderLength = KeyUtility.iHeaderLength; // Console.WriteLine("iModulusBits=" + _iModulusBits.ToString() + " | " + KeyUtility.iModulusBits.ToString()); // Console.WriteLine("iExponentBits=" + _iExponentBits.ToString() + " | " + KeyUtility.iExponentBits.ToString()); // Console.WriteLine("abRawBytes.Length=" + _abRawBytes.Length.ToString() + " | " + KeyUtility.abRawBytes.Length.ToString()); } else { throw new FormatException("PgpPublicKey.EncodeRawBytes()"); } }