使用tomcrypt

时间:2015-04-22 13:01:59

标签: encryption cryptography rsa public-key-encryption libtomcrypt

我是密码学的新手。开始时需要一些帮助。

我有模数字段&服务器给出的Private Exponent字段,我需要使用Tomcrypt库从中组成私钥。

我无法弄清楚来自tomcrypt的哪个Api会为我做这个。 如果有人能让我知道api或者它的步骤,那将是神圣的。

由于

1 个答案:

答案 0 :(得分:0)

我不确定tomcrypt是否支持从给定的私有指数和模数字段生成私钥。但是,tomcrypt提供了rsa_make_key函数来生成密钥。然后可以使用rsa_export函数从这些键导出公钥/私钥。

/** 
   Create an RSA key
   @param prng     An active PRNG state
   @param wprng    The index of the PRNG desired
   @param size     The size of the modulus (key size) desired (octets)
   @param e        The "e" value (public key).  e==65537 is a good choice
   @param key      [out] Destination of a newly created private key pair
   @return CRYPT_OK if successful, upon error all allocated ram is freed
*/
int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key)

/**
    This will export either an RSAPublicKey or RSAPrivateKey [defined in LTC_PKCS #1 v2.1] 
    @param out       [out] Destination of the packet
    @param outlen    [in/out] The max size and resulting size of the packet
    @param type      The type of exported key (PK_PRIVATE or PK_PUBLIC)
    @param key       The RSA key to export
    @return CRYPT_OK if successful
*/
int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
相关问题