VeriBlock / nodecore

Other
12 stars 16 forks source link

Encoding & decoding public/private keys #24

Closed j0k closed 5 years ago

j0k commented 5 years ago

I see that public key corresponds X509EncodedKeySpec and private key corresponds PKCS8EncodedKeySpec standard.

In tests there are two examples for keys both private and public:

The question: Why both different pairs have the same beginning? How did you get the source for the Base64 PUBLIC & PRIVATE KEYS?

For example:

PUBLIC_KEY1 = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAERma1mS2caMSQHp4fV/UbRipyQCu47VOik8oQze9SA3EMxuLWlTHBBEYWALFBTxpcd99ksgWaOmGxAdfJ9Ybctg=="
PUBLIC_KEY2 = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE1FUzpjM/Dv8gLfOND6GxuJXPHDPIDWPp0C0ju6DyiTCCVGKyb3KrVpP+o1RPyXqSlD8YxMk9qadeuCPgGkvtlA=="

in hex they have similar first 23 bytes ((176-130)/2 ) after Base64 decoding

pubKeyHex1 = "3056301006072a8648ce3d020106052b8104000a034200044666b5992d9c68c4901e9e1f57f51b462a72402bb8ed53a293ca10cdef5203710cc6e2d69531c104461600b1414f1a5c77df64b2059a3a61b101d7c9f586dcb6"
pubKeyHex2 = "3056301006072a8648ce3d020106052b8104000a03420004d45533a6333f0eff202df38d0fa1b1b895cf1c33c80d63e9d02d23bba0f28930825462b26f72ab5693fea3544fc97a92943f18c4c93da9a75eb823e01a4bed94"

last 65 bytes looks like real public key for the ECDSA.

What's the original structure of PUBLIC_KEY/PRIVATE_KEY?)

timstall commented 5 years ago

solved with https://github.com/VeriBlock/nodecore-js