예제 #1
0
        /// <summary>
        /// Creates a new secret key packet. Format defaults
        /// to new packet format.
        /// </summary>
        /// <param name="bIsSubkey">Has to be true, if you want
        /// to create a secret subkey packet.</param>
        public SecretKeyPacket(bool bIsSubkey)
        {
            bBody         = new byte[0];
            bHeader       = new byte[0];
            pfFormat      = PacketFormats.New;
            bIsEncrypted  = true;
            bS2KSpecifier = new String2KeySpecifier();
            bS2KSpecifier.HashAlgorithm = HashAlgorithms.SHA1;
            bS2KSpecifier.Type          = String2KeySpecifierTypes.IteraterSaltedS2K;
            bS2KSpecifier.Count         = 96;

            byte[] bSalt = new byte[8];
            System.Security.Cryptography.RandomNumberGenerator rngRand = System.Security.Cryptography.RandomNumberGenerator.Create();
            rngRand.GetBytes(bSalt);

            S2KSpecifier.Salt = 0;
            S2KSpecifier.Salt = ((ulong)bSalt[0] << 56) ^ ((ulong)bSalt[1] << 48) ^
                                ((ulong)bSalt[2] << 40) ^ ((ulong)bSalt[3] << 32) ^
                                ((ulong)bSalt[3] << 24) ^ ((ulong)bSalt[5] << 16) ^
                                ((ulong)bSalt[6] << 8) ^ (ulong)bSalt[7];

            if (bIsSubkey)
            {
                ctContent = ContentTypes.SecretSubkey;
            }
            else
            {
                ctContent = ContentTypes.SecretKey;
            }

            this.bIsUpdated = true;
        }
 /// <summary>
 /// Creates a new SymSessionKeyPacket with
 /// the parameters in pSource
 /// </summary>
 /// <param name="pSource">Packet from which the
 /// parameters are derived</param>
 public SymSessionKeyPacket(Packet pSource)
 {
     lLength             = pSource.Length;
     bBody               = pSource.Body;
     ctContent           = pSource.Content;
     pfFormat            = pSource.Format;
     bHeader             = pSource.Header;
     EncryptedSessionKey = new byte[0];
     s2kSpecifier        = new String2KeySpecifier();
     this.bIsUpdated     = false;
 }
        /// <summary>
        /// Creates a new symmetrical session key packet. Format defaults
        /// to new packet format.
        /// </summary>
        public SymSessionKeyPacket()
        {
            bBody     = new byte[0];
            bHeader   = new byte[0];
            pfFormat  = PacketFormats.New;
            ctContent = ContentTypes.SymSessionKey;
            this.bEncryptedSessionKey = new byte[0];

            s2kSpecifier       = new String2KeySpecifier();
            s2kSpecifier.Type  = String2KeySpecifierTypes.IteraterSaltedS2K;
            s2kSpecifier.Count = 96;

            byte[] bSalt = new byte[8];
            System.Security.Cryptography.RandomNumberGenerator rngRand = System.Security.Cryptography.RandomNumberGenerator.Create();
            rngRand.GetBytes(bSalt);

            S2KSpecifier.Salt = 0;
            S2KSpecifier.Salt = ((ulong)bSalt[0] << 56) ^ ((ulong)bSalt[1] << 48) ^
                                ((ulong)bSalt[2] << 40) ^ ((ulong)bSalt[3] << 32) ^
                                ((ulong)bSalt[3] << 24) ^ ((ulong)bSalt[5] << 16) ^
                                ((ulong)bSalt[6] << 8) ^ (ulong)bSalt[7];
            this.bIsUpdated = true;
        }