【问题标题】:How does libsodium generate a keypairlibsodium 如何生成密钥对
【发布时间】:2015-10-07 10:55:48
【问题描述】:

对于 libsodium 中的 public key encryptiondiffie-hellman,我通常通过使用 randombytes_buf 生成 32 个随机字节来制作私钥,然后使用 crypto_scalarmult_base 导出公钥(在需要时)。

使用crypto_box_keypair 生成密钥对(除了语法)有什么好处吗?或者这个功能基本上就是这样做的?

【问题讨论】:

    标签: encryption libsodium nacl-cryptography


    【解决方案1】:

    这正是crypto_box_keypair() 函数的作用。

    此功能的好处是清晰,并保证正确生成密钥。

    【讨论】:

    • 一旦 crypto_box_keypair() 函数返回一个公钥和私钥 - 它们作为 uint8 数组返回 -> 如何将它们转换为可用字符串(以 json 格式发送) sodium.to_string 似乎没有上班
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      • 2021-01-06
      • 2018-12-21
      相关资源
      最近更新 更多