Yii2 RSA encrypt using Modulus and Exponent

Viewed 235

I have a soap web service that requires password encryption using RSA algorithm. However, I was given steps on how to go about this, but I am not really clear on what exactly to be doing.

Steps

  1. Perform a SHA-256 hash of the password
  2. Convert the BigInteger of the representation of the SHA-256 to a string on a base of16
  3. Encrypt the key using a public key with the following parameters

    Exponent 113621440243785421499955306133900099987164309503876199371900 61108597569919490562171044287644188919530245192244355535426664573745 this isn't a real value but just a guide)

    Modulus 9965644084057417656330538552189694824948559788786878830575584 44367368137357168893841560814041088567854117014580575728077016098213 (this isn't a real value but just a guide)

  4. Perform a base64 encode of the password

What I have done is to read up on RSA algorithm and came across some working examples online but when I implemented those samples, I kept getting same error message that "can't decrypt the password"

$client = Yii::$app->soapApi; //the soapApi component was declared inside the main.php file

  $password = 'abc12345';

  $password = hash("sha256", $password);

  $r = gmp_init($password, 16);
  $result =  gmp_strval($r); 

  $exponent= 'value was specified here';

  $modulus= 'value was specified here';

  $crypt_rsa = new \Crypt_RSA();
  $crypt_rsa->loadKey(
     array(
         'e' => new \Math_BigInteger($exponent),
         'n' => new \Math_BigInteger($modulus)
     )
  );

  $encryptedPassword = base64_encode($crypt_rsa->encrypt($result));

  $parameters = [
    'username' =>'username',
    'password' => $encryptedPassword,
    'orgid' => 'value'
  ];

  var_dump($client->createTokenString($parameters));die;

I expected the result to return an element with a generated token but what I get is can't decrypt password

0 Answers
Related