Search code examples
clibsodiumed25519

libsodium ed25519 key generator printing


I am trying to generate keys using libsoudium and printing them. Where are thees keys stored and how can I find them? This is what I am trying to do in C.

unsigned char pk[crypto_sign_PUBLICKEYBYTES];
    unsigned char sk[crypto_sign_SECRETKEYBYTES];
    int crypto_sign_keypair(unsigned char *pk, unsigned char *sk);
    printf("%s", pk);

this outputs: H��H�. What does that mean?

the documentation is here for the functions I am trying to call. https://download.libsodium.org/doc/public-key_cryptography/public-key_signatures.html


Solution

  • While the keys are composed of some number of char there's no guarantee the characters be visible ASCII characters. I think you probably want to print them with a loop similar to this;

    for(i=0;i<crypto_sign_PUBLICKEYBYTES;i++)
        printf("%2.2x",pk[i]);
    puts("");