首页 > 解决方案 > libsodium ed25519 密钥生成器打印

问题描述

我正在尝试使用 libsoudium 生成密钥并打印它们。这些密钥存储在哪里,我如何找到它们?这就是我在 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);

这输出:H��H�。这意味着什么?

文档在这里是我试图调用的函数。 https://download.libsodium.org/doc/public-key_cryptography/public-key_signatures.html

标签: clibsodiumed25519

解决方案


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

例如:

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);

推荐阅读