Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert key to binary

1,169 views
Skip to first unread message

Duke

unread,
Oct 9, 2001, 2:31:19 PM10/9/01
to
I am working on a project and need to convert keys to binary format for
storage. The current PGPfreeware no longer exports keys to binary, only to
what used to be called 'ASCII armored' (which now isn't called anything
anymore since it's the only option ;)
I'll take just the theory or if redily available the code in C (or Java or
whatever). The key will be stored in a byte array.
I am hoping the official format does something to 'compress' the size in
bytes, not just writing the ASCII code into a full byte.
Thx


disa...@hackserv.saiknes.lv

unread,
Oct 10, 2001, 2:51:08 AM10/10/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

gpg --output keys.pgp --dearmor keys.asc


== <EOF> ==
Disastry http://i.am/disastry/
http://disastry.dhs.org/pgp <----PGP plugins for Netscape and MDaemon
^--GPG for Win32 (supports loadable modules and IDEA)
^----PGP 2.6.3ia-multi05 (supports IDEA, CAST5, BLOWFISH, TWOFISH,
AES, 3DES ciphers and MD5, SHA1, RIPEMD160, SHA2 hashes)
-----BEGIN PGP SIGNATURE-----
Version: Netscape PGP half-Plugin 0.14 by Disastry / PGPsdk v1.7.1

iQA/AwUBO8PTnzBaTVEuJQxkEQPooACgsT9+9tqng9xZEB2hgEs6ui4LymAAoKKn
5NBQ/xTfey4ZuCSo1wr1TDP6
=QPtn
-----END PGP SIGNATURE-----

disa...@saiknes.lv.no.spam.net

unread,
Oct 10, 2001, 2:51:33 AM10/10/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

gpg --output keys.pgp --dearmor keys.asc

Duke

unread,
Oct 10, 2001, 4:50:15 PM10/10/01
to
<disa...@hackserv.saiknes.lv> wrote in message
news:3BC3EFDC...@saiknes.lv.NO.SPaM.NET...

> gpg --output keys.pgp --dearmor keys.asc

Perhaps I was not overly clear in my original message - I am looking for a
way to _programatically_ convert a key. Or make sense of the the
pubring,pkr & secring.skr files. Are you inferring that I take a look at
the gpg source code? I would rather have a format specification on both the
file formats and the [binary] key format.

P.S. I am assuming that the command you suggested will output all keys into
a binary file (keys.pgp). This would again not be of much use since I don't
know the format of the file and I wouldn't know where one key ends and the
other begins. I am mostly concerned with Win32 platforms, and with private
keys (storing them onto a removable device that is spacelimited). So, I
need a way to convert the output of PGP for windows exporting a key
(currently only to base-64 ASCII format) to binary, to optimize storage
space. As it's been suggested elsewhere, I could just hack it myself and
pack 4 base-64 characters into 3 bytes, but I am wondering if there is a
better way.


disa...@saiknes.lv.no.spam.net

unread,
Oct 11, 2001, 2:03:50 AM10/11/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Duke wrote:
> <disa...@hackserv.saiknes.lv> wrote in message
> news:3BC3EFDC...@saiknes.lv.NO.SPaM.NET...
> > gpg --output keys.pgp --dearmor keys.asc
>
> Perhaps I was not overly clear in my original message - I am looking for a
> way to _programatically_ convert a key.

I see...
it's BASE64 encoded, it shouldn't be hard to find how to decode it,
or even ready made functions for that.

> Or make sense of the the pubring,pkr & secring.skr files.
> Are you inferring that I take a look at the gpg source code?

you can do, but thats probably not the easiest way..

> I would rather have a format specification on both the
> file formats and the [binary] key format.

see RFC 2440

> P.S. I am assuming that the command you suggested will output all keys into
> a binary file (keys.pgp). This would again not be of much use since I don't
> know the format of the file

see RFC 2440

> and I wouldn't know where one key ends and the
> other begins. I am mostly concerned with Win32 platforms, and with private
> keys (storing them onto a removable device that is spacelimited). So, I
> need a way to convert the output of PGP for windows exporting a key
> (currently only to base-64 ASCII format) to binary, to optimize storage
> space. As it's been suggested elsewhere, I could just hack it myself and
> pack 4 base-64 characters into 3 bytes, but I am wondering if there is a
> better way.

it's not only best, but only way.
and you'll probaly want to remove signatures (and
maybe even user-ids) from key so that it is smaller..

== <EOF> ==
Disastry http://i.am/disastry/
http://disastry.dhs.org/pgp <----PGP plugins for Netscape and MDaemon
^--GPG for Win32 (supports loadable modules and IDEA)
^----PGP 2.6.3ia-multi05 (supports IDEA, CAST5, BLOWFISH, TWOFISH,
AES, 3DES ciphers and MD5, SHA1, RIPEMD160, SHA2 hashes)
-----BEGIN PGP SIGNATURE-----
Version: Netscape PGP half-Plugin 0.14 by Disastry / PGPsdk v1.7.1

iQA/AwUBO8UZ+DBaTVEuJQxkEQOyEQCg5asM7iH40kbEKO2g+w4bGvSvI0YAoMZD
oZT+0vyloN4keJIRePeEdvc0
=yQ65
-----END PGP SIGNATURE-----

Duke

unread,
Oct 12, 2001, 11:54:48 AM10/12/01
to
<disa...@saiknes.lv.NO.SPaM.NET> wrote in message
news:3BC53646...@saiknes.lv.NO.SPaM.NET...

> > I would rather have a format specification on both the
> > file formats and the [binary] key format.
>
> see RFC 2440

U da man! I'm working with it right now.

Funny how even PGP 7.0.3 uses what GPG calls 'Old format' packet headers ;)


disa...@saiknes.lv.no.spam.net

unread,
Oct 12, 2001, 12:29:28 PM10/12/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Duke wrote:
> > > I would rather have a format specification on both the
> > > file formats and the [binary] key format.
> >
> > see RFC 2440
>
> U da man! I'm working with it right now.
>
> Funny how even PGP 7.0.3 uses what GPG calls 'Old format' packet headers ;)

and even GPG does ;)

'old' not always means 'bad' :)

__
Disastry http://disastry.dhs.org/


http://disastry.dhs.org/pgp <----PGP plugins for Netscape and MDaemon
^--GPG for Win32 (supports loadable modules and IDEA)
^----PGP 2.6.3ia-multi05 (supports IDEA, CAST5, BLOWFISH, TWOFISH,
AES, 3DES ciphers and MD5, SHA1, RIPEMD160, SHA2 hashes)
-----BEGIN PGP SIGNATURE-----
Version: Netscape PGP half-Plugin 0.14 by Disastry / PGPsdk v1.7.1

iQA/AwUBO8b+MzBaTVEuJQxkEQPRxgCfTH0YJ/C0RHPGzP9XU4zRdZiqKRwAn2ke
LgziNdFi+m/+gxWWc+R++jyB
=jQJb
-----END PGP SIGNATURE-----

Duke

unread,
Oct 12, 2001, 12:38:34 PM10/12/01
to
First 3 bytes of my private key (hex):
95 01 CF

95 = 10010101 which tells me this is an old format header, private key
packet, 2-octet length follows.

Then from the RFC:
---
3.1 Scalar numbers
Scalar numbers are unsigned, and are always stored in big-endian format.
---
AND
---
4.2.2.2 Two-Octet Lengths
A two-octet Body Length header encodes a length of from 192 to 8383 octets.
It is recognized because its first octet is in the range 192 to 223. The
body length is equal to:

bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
---
So, if this big-endian, 01 is MSB and CF LSB. However, this doesn't fly
when plugged into bodyLen = ((0x01 - 192) << 8) + (0xCF) + 192. It looks to
me like it's in little-endian format. If I plug it in little endian format,
I end up with 4033. But the file is larger than 4036 bytes (4033 + 3 byte
header).

Then onto byte 4037, which I assume to be the PTag of another header (this
is a DH/DSS key so 2 keys, right?):
C4 or 11000100
So, mixed Header types (first key old header format, new key new header
format???). RFC just says:
---
New format packets contain:
Bits 5-0 -- content tag
---
So how the heck do I know how many bytes follow encoding packet length???

Hopefully a kind soul who's been thru this can help me out. Once I get all
this sorted out I should be in business.


disa...@saiknes.lv.no.spam.net

unread,
Oct 12, 2001, 1:08:48 PM10/12/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Duke wrote:
> First 3 bytes of my private key (hex):
> 95 01 CF

or get pgpdump, it will show all the packets

or do
gpg --list-packets file
it will also show packets
__
Disastry http://disastry.dhs.org/


http://disastry.dhs.org/pgp <----PGP plugins for Netscape and MDaemon
^--GPG for Win32 (supports loadable modules and IDEA)
^----PGP 2.6.3ia-multi05 (supports IDEA, CAST5, BLOWFISH, TWOFISH,
AES, 3DES ciphers and MD5, SHA1, RIPEMD160, SHA2 hashes)
-----BEGIN PGP SIGNATURE-----
Version: Netscape PGP half-Plugin 0.14 by Disastry / PGPsdk v1.7.1

iQA/AwUBO8cHeDBaTVEuJQxkEQMAOwCgjm/LW5SC0llIiqx/bqTVU0s764AAoMcK
73+2Os0y3PJzVVstw16kdknr
=P8eL
-----END PGP SIGNATURE-----

disa...@saiknes.lv.no.spam.net

unread,
Oct 12, 2001, 1:05:51 PM10/12/01
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Duke wrote:
> First 3 bytes of my private key (hex):
> 95 01 CF
>
> 95 = 10010101 which tells me this is an old format header, private key
> packet, 2-octet length follows.
>
> Then from the RFC:
> ---
> 3.1 Scalar numbers
> Scalar numbers are unsigned, and are always stored in big-endian format.
> ---
> AND
> ---
> 4.2.2.2 Two-Octet Lengths
> A two-octet Body Length header encodes a length of from 192 to 8383 octets.
> It is recognized because its first octet is in the range 192 to 223. The
> body length is equal to:
>
> bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192

it is old packet so 4.2.1 aplies, not the 4.2.2.2
so bodyLen = 0x1CF = 463

> ---
> New format packets contain:
> Bits 5-0 -- content tag

it is old packet, tag = 0101 = 5 = Secret Key Packet

__
Disastry http://disastry.dhs.org/


http://disastry.dhs.org/pgp <----PGP plugins for Netscape and MDaemon
^--GPG for Win32 (supports loadable modules and IDEA)
^----PGP 2.6.3ia-multi05 (supports IDEA, CAST5, BLOWFISH, TWOFISH,
AES, 3DES ciphers and MD5, SHA1, RIPEMD160, SHA2 hashes)
-----BEGIN PGP SIGNATURE-----
Version: Netscape PGP half-Plugin 0.14 by Disastry / PGPsdk v1.7.1

iQA/AwUBO8cGxjBaTVEuJQxkEQOl3QCfdK29nGmdjiuKSgvZ9c5ejX9e+W8An1uR
jFyYf+bUlp1exStNyVi9JI84
=K741
-----END PGP SIGNATURE-----

Duke

unread,
Oct 12, 2001, 1:53:10 PM10/12/01
to
<disa...@saiknes.lv.NO.SPaM.NET> wrote in message
news:3BC722EF...@saiknes.lv.NO.SPaM.NET...

> it is old packet so 4.2.1 aplies, not the 4.2.2.2
> so bodyLen = 0x1CF = 463

Got it.

> or get pgpdump, it will show all the packets

Perfect!

Thx


0 new messages