我在C中使用这个代码,使用openssl库来计算bignumber的SHA1摘要。 我如何在Ruby中翻译这段代码?
#include <stdio.h>
#include <openssl/sha.h>
#include <openssl/bn.h>
int
main ()
{
// Create a bignum = 3
struct bignum_st *bn = BN_new ();
BN_set_word (bn, 3);
// Initialize SHA1 context
unsigned char digest[SHA_DIGEST_LENGTH];
SHA_CTX sha_ctx;
SHA1_Init (&sha_ctx);
// Calculate SHA1 digest (in binary) of bignum 3
SHA1_Update (&sha_ctx, bn, BN_num_bytes (bn));
SHA1_Final (digest, &sha_ctx);
// Print HEX value of digest
int i;
for (i = 0; i < SHA_DIGEST_LENGTH; i++)
printf ("%x", digest[i]);
printf ("\n");
// result is: 516b9783fca517eecbd1d064da2d165310b19759
}
编译:{{1}}
THX。