PHP rsa get public key from pem file

后端 未结 3 676
清歌不尽
清歌不尽 2021-01-15 05:05

How can i get publickey from pem file which is created based on rsa 364. installed crypt(RSA.php) library still getting below error

Fatal error: Call to unde

相关标签:
3条回答
  • 2021-01-15 05:19

    According to the Crypt_RSA documentation, the Crypt_RSA class doesn't have a loadKey() method. You pass the public key to the constructor as part of an associative array of parameters:

    $rsa_obj = new Crypt_RSA(array('public_key' => $publickey));
    
    0 讨论(0)
  • 2021-01-15 05:19

    this is how to load public key in a php and how to know the number of bits used in its encryption and how to encrypt data. remember to split the data into chunks with maximum size of key bytes size.

    <?php
    
    // Get the public Key 
    $pubKey = file_get_contents("public.key");
    
    //echo $pubKey; echo "<br>";
    
    $res=openssl_get_publickey($pubKey);   //convert pubkey into resource
    $array=openssl_pkey_get_details($res); //read the resource details
    $chunksize= $array['bits'];            //this is the chunk size 4096
    
    
    $data = 'plaintext data goes here, please encrypt and decrypt the following data';
    openssl_public_encrypt($data, $encrypted, $pubKey);
    ?>
    
    0 讨论(0)
  • 2021-01-15 05:28

    My recommendation: don't use PEAR's Crypt_RSA but rather phpseclib's Crypt_RSA.

    PEAR's Crypt_RSA isn't PKCS#1 compliant, meaning signatures or ciphertexst's generated with it are not going to be interoperable with other languages, it doesn't support passworded private keys, and hasn't been actively maintained for years.

    More info on phpseclib:

    http://phpseclib.sourceforge.net/

    0 讨论(0)
提交回复
热议问题