1

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

nope
  • 47
  • 5

2 Answers2

1

https://download.libsodium.org/doc/public-key_cryptography/public-key_signatures.html

for example:

unsigned char pk[crypto_sign_PUBLICKEYBYTES]; //Variable declarations
unsigned char sk[crypto_sign_SECRETKEYBYTES]; Variable declarations
crypto_sign_keypair(pk, sk);

NSData *privateKeyData = [NSData dataWithBytes:sk length:crypto_box_SECRETKEYBYTES];
NSData *publicKeyData = [NSData dataWithBytes:pk length:crypto_box_PUBLICKEYBYTES];

NSLog(@"%@",privateKeyData);  // target publick key data and secret key data
NSLog(@"%@",publicKeyData);  
//Other 
NSLog(@"%s\n\n=====\n\n\n%s",pk,sk); //(nullable const void *)bytes
Byte *byte = (Byte *)[publicKeyData bytes];
NSLog(@"%s",byte);
Qun Li
  • 1,256
  • 13
  • 13
0

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("");
cleblanc
  • 3,678
  • 1
  • 13
  • 16