我使用nacl加密库,需要从中恢复公钥 密钥。这可能吗?
这是我有点天真的尝试:
#include <nacl/crypto_scalarmult_curve25519.h>
#include <nacl/crypto_sign.h>
//...
int main(int argc, char **argv)
{
UCHAR pk[crypto_sign_PUBLICKEYBYTES];
UCHAR sk[crypto_sign_SECRETKEYBYTES];
char pkhexbuf[2*crypto_sign_PUBLICKEYBYTES+1];
char skhexbuf[2*crypto_sign_SECRETKEYBYTES+1];
if( crypto_sign_keypair( pk, sk ) != 0) {
printf( "Failed to generate keys." );
return 1;
}
printf( "public key: %s\n", bytes_to_hex( pkhexbuf, pk, sizeof(pk) ) );
printf( "secret key: %s\n", bytes_to_hex( skhexbuf, sk, sizeof(sk) ) );
//reset the public key
memset(pk, '\0', sizeof(pk));
//recover public key
if( crypto_scalarmult_curve25519_base(pk, sk) != 0 ) {
printf( "Failed to derive public key from secret key." );
return 1;
}
printf( "public key: %s\n", bytes_to_hex( pkhexbuf, pk, sizeof(pk) ) );
return 0;
}
公钥不匹配。有任何想法应该怎么做?