Follow

Password encryption in PHP (java, etc.)

The password must be encrypted using the following public key:

-----BEGIN PUBLIC KEY-----

MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMLrpmZu3cBDlbw8dg71kuaGsq

2rbpyS8KwazYZcC1imRWt7WguSpe3dcQKB49QHQOX4Va512C0XqrNtR3qte3hkju

/A8wslpcvpX9sk0blDdsG4IwN8PDw9c0aZxaRGXDo09aILlhYqHkzBetWrlDbO3O

CHhnF9XSAJTpnWzeWQIDAQAB

-----END PUBLIC KEY-----

After the encryption, the result string must be encoded to base64.

Each language provides different ways to encrypt strings and they are easily found on the Internet.

Here you find an example in PHP (please replace the password to encrypt yours):

<?php

 $publicKey = "-----BEGIN PUBLIC KEY-----

MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMLrpmZu3cBDlbw8dg71kuaGsq

2rbpyS8KwazYZcC1imRWt7WguSpe3dcQKB49QHQOX4Va512C0XqrNtR3qte3hkju

/A8wslpcvpX9sk0blDdsG4IwN8PDw9c0aZxaRGXDo09aILlhYqHkzBetWrlDbO3O

CHhnF9XSAJTpnWzeWQIDAQAB

-----END PUBLIC KEY-----";

  $passwordToEncrypt = "Password1!";

  $passwordEncrypted = Encrypt($publicKey, $passwordToEncrypt);

  var_dump($passwordEncrypted);

 

  function Encrypt($publicKey, $data)

  {

    $publicKey = openssl_pkey_get_public($publicKey);

    $encryptedString = "";

   

    if (!is_resource($publicKey))

      return $encryptedString;

   

    $success = openssl_public_encrypt ($data , $encryptedString , $publicKey);

    if ($success)

      $encryptedString = base64_encode($encryptedString);

   

    return $encryptedString;

  }

?>

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments