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9ICAxUytRq3gO/caWSNsbAoWrZMnqHqrSyelFSA2wWvUqf
> HhG3VBBBw11vzshfVk7cM07sk3lGwBMNI+s2W69BVPYol0y2yccdnx1HQ6iLkEkj
> x515M/Ny2CqNwyLnbmf71jvotH6uAAD2Lk4wXWygbwYSc5Df6+BpKz0j5fGfMcie
> Y6M75UDhOA++iEkEGBECAAkFAlh+OvsCGwwACgkQz7LAX9cOtPjcJgCdG8Y7L5a3
> yOJBa1iWGGdDa4zwh7cAn3pXu5TkvyjpGD48Whrk3DiaW9LG
> =HFIX
> -----END PGP PRIVATE KEY BLOCK-----

My task is to change the secret key to another value. By doing this I also have to change the length of the packet and the checksum.

Which part of this key block is what? I can't find a good list about which flag sits where.

$\endgroup$
5
  • 1
    $\begingroup$ Does this answer your question PGP public RSA key format $\endgroup$ – kelalaka Jan 9 at 13:36
  • $\begingroup$ @kelalaka Does that also show information about the private key block? $\endgroup$ – Maarten Bodewes Jan 9 at 17:16
  • $\begingroup$ @MaartenBodewes according to my testing, this key created in 2017 and pgpdump can print information. $\endgroup$ – kelalaka Jan 9 at 17:24
  • $\begingroup$ Yeah, just using a tool that can dump information about PGP packets would do I suppse. $\endgroup$ – Maarten Bodewes Jan 9 at 17:25
  • 1
    $\begingroup$ Starts with old: Secret Key Packet(tag 5)(443 bytes). pgpdump provides all information. So only one needs to decode base64, modify, and encode with base64. $\endgroup$ – kelalaka Jan 9 at 17:33
0
$\begingroup$

The pgpdump command list all of the information. The below

pgpdump private_key_file.txt -l -u

is used to dump contents. As one can see it is well regulated.

Old: Secret Key Packet(tag 5)(443 bytes)
        Ver 4 - new
        Public key creation time - Tue Jan 17 15:40:43 UTC 2017
        Pub alg - DSA Digital Signature Algorithm(pub 17)
        DSA p(1024 bits) - ...
        DSA q(160 bits) - ...
        DSA g(1024 bits) - ...
        DSA y(1019 bits) - ...
        DSA x(160 bits) - ...
        Checksum - 08 f2 
Old: User ID Packet(tag 13)(18 bytes)
        User ID - Bobby <bob@rub.de>
Old: Signature Packet(tag 2)(97 bytes)
        Ver 4 - new
        Sig type - Positive certification of a User ID and Public Key packet(0x13).
        Pub alg - DSA Digital Signature Algorithm(pub 17)
        Hash alg - SHA1(hash 2)
        Hashed Sub: signature creation time(sub 2)(4 bytes)
                Time - Tue Jan 17 15:40:43 UTC 2017
        Hashed Sub: key flags(sub 27)(1 bytes)
                Flag - This key may be used to certify other keys
                Flag - This key may be used to sign data
        Hashed Sub: preferred symmetric algorithms(sub 11)(4 bytes)
                Sym alg - AES with 256-bit key(sym 9)
                Sym alg - AES with 192-bit key(sym 8)
                Sym alg - AES with 128-bit key(sym 7)
                Sym alg - Triple-DES(sym 2)
        Hashed Sub: preferred hash algorithms(sub 21)(5 bytes)
                Hash alg - SHA256(hash 8)
                Hash alg - SHA384(hash 9)
                Hash alg - SHA512(hash 10)
                Hash alg - SHA224(hash 11)
                Hash alg - SHA1(hash 2)
        Hashed Sub: preferred compression algorithms(sub 22)(3 bytes)
                Comp alg - ZLIB <RFC1950>(comp 2)
                Comp alg - BZip2(comp 3)
                Comp alg - ZIP <RFC1951>(comp 1)
        Hashed Sub: features(sub 30)(1 bytes)
                Flag - Modification detection (packets 18 and 19)
        Hashed Sub: key server preferences(sub 23)(1 bytes)
                Flag - No-modify
        Sub: issuer key ID(sub 16)(8 bytes)
                Key ID - 0xCFB2C05FD70EB4F8
        Hash left 2 bytes - 4f ea 
        DSA r(160 bits) - ...
        DSA s(159 bits) - ...
                -> hash(DSA q bits)
Old: Secret Subkey Packet(tag 7)(305 bytes)
        Ver 4 - new
        Public key creation time - Tue Jan 17 15:40:43 UTC 2017
        Pub alg - ElGamal Encrypt-Only(pub 16)
        ElGamal p(1024 bits) - ...
        ElGamal g(3 bits) - ...
        ElGamal y(1022 bits) - ...
        ElGamal x(246 bits) - ...
        Checksum - 0f be 
Old: Signature Packet(tag 2)(73 bytes)
        Ver 4 - new
        Sig type - Subkey Binding Signature(0x18).
        Pub alg - DSA Digital Signature Algorithm(pub 17)
        Hash alg - SHA1(hash 2)
        Hashed Sub: signature creation time(sub 2)(4 bytes)
                Time - Tue Jan 17 15:40:43 UTC 2017
        Hashed Sub: key flags(sub 27)(1 bytes)
                Flag - This key may be used to encrypt communications
                Flag - This key may be used to encrypt storage
        Sub: issuer key ID(sub 16)(8 bytes)
                Key ID - 0xCFB2C05FD70EB4F8
        Hash left 2 bytes - dc 26 
        DSA r(157 bits) - ...
        DSA s(159 bits) - ...
                -> hash(DSA q bits)

If one uses the -u option, too, then it will print the values, too.

DSA x(160 bits) - 8d 5d 6a 83 d8 40 ed 59 16 23 76 8b b8 9e 60 60 25 29 65 1a

The file is encoded with Base64. Therefore, you need to decode the base64 which results in bytes. Locate the necessary information by using the information from the dump, or read the rfc4880. The first octet (byte) of the packet header is called the Packet Tag, see in the dump.

A cleaver act is using the source file of pgpdump or similar to locate values, change them, and print them back.

The numbers are stored in big-endian, act according to this information.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.