000023726 - How to retrieve the modulus value given a BER encoded public key

Document created by RSA Customer Support Employee on Jun 16, 2016Last modified by RSA Customer Support Employee on Apr 21, 2017
Version 2Show Document
  • View in full screen mode

Article Content

Article Number000023726
Applies ToBSAFE/Crypto-C 6.3.1 or earlier
IssueHow to retrieve the modulus value given a BER encoded public key
User has a PKCS#1 BER-encoded public key and would like to find out the modulus value.
Resolution

First, use B_SetKeyInfo() to set the BER data into a key object.  Then, use B_GetKeyInfo() to get the info out in modulus exponent form.  Like below:

B_KEY_OBJ publicKey = (B_KEY_OBJ)NULL_PTR;
A_RSA_KEY *getPublicKey = (A_RSA_KEY *)NULL_PTR;
ITEM publicBER = {NULL, 0};
int status;

do {
  RSA_PrintMessage ("Enter the filename for the public key BER");
  if ((status = RSA_GetFileToAllocBuffer
    (&publicBER.data, &publicBER.len," (blank to cancel)")) != 0)
    break;

  if ((status = B_CreateKeyObject (&publicKey)) != 0)
    break;

  /* set the BER data into the key object */
  if ((status = B_SetKeyInfo (publicKey, KI_RSAPublicBER, (POINTER)&publicBER)) != 0)
    break;

  /* get the key data out in modulus exponent form */
  if ((status = B_GetKeyInfo ((POINTER *)&getPublicKey, publicKey, KI_RSAPublic)) != 0)
    break;

  /* here are the modulus data and exponent values that you can get
  getPublicKey->modulus.data
  getPublicKey->modulus.len
  getPublicKey->exponent.data
  getPublicKey->exponent.len
  */
} while (0);


if (status != 0)
{
  RSA_PrintError ("Error in getting public key modulus", status);
}

Legacy Article IDa35210

Attachments

    Outcomes