a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by lcguedes
lcguedes  ·  4261 days ago  ·  link  ·    ·  parent  ·  post: A simple hexadecimal "bignum" library, in C.

Sorry about the expmod function. As you said, I have just renamed it.

This decrypt function works only for data encrypted with the private key (d,n). Thus, it is useful for checking signatures not for decrypting actual data.

if you try the code below you will see it will fail:

   HB_hex_string_to_hex_bignum( TEST_PUBLIC_KEY_EXP, &(publicKey.e) );

   HB_hex_string_to_hex_bignum( TEST_PUBLIC_KEY_MOD, &(publicKey.n) );

   HB_int_to_hex_bignum( 0, &privateKey.e );
   HB_int_to_hex_bignum( 0, &privateKey.n );

   HB_hex_string_to_hex_bignum( TEST_RESULT, &rsaOrig );

   rsaEncrypt( &rsaOrig, &rsaEncrypted, &publicKey );

   rsaDecrypt( &rsaEncrypted, &rsaDecrypted, &publicKey );

   if ( HB_compare( &rsaOrig, &rsaDecrypted ) == 0 )
   {
      printf( "Passed!\n" );
   }
   else
   {
      printf( "Failed!\n" );
   }




briandmyers  ·  4261 days ago  ·  link  ·  
This comment has been deleted.
briandmyers  ·  4261 days ago  ·  link  ·  

If you encrypt data with the public key, you must decrypt it with the private key, not the public key.