【问题标题】:libsodium ed25519 key generator printinglibsodium ed25519 密钥生成器打印
【发布时间】:2018-06-25 18:04:15
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: c libsodium ed25519


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      虽然键由一定数量的char 组成,但不能保证这些字符是可见的 ASCII 字符。我想你可能想用类似这样的循环来打印它们;

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-09-30
        • 1970-01-01
        • 2022-07-26
        • 1970-01-01
        • 2022-07-14
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多