Generate DES-EDE3-CBC using PHPSECLIB in PHP

Hi tyros!

Im working in a project, where i need to generate "RSA PRIVATE KEY". Like this:


-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,374EC0DDDDD1CC77

OXbtzz...
-----END RSA PRIVATE KEY-----


First, add this lines:

use phpseclib\Crypt\RSA as RSA;
use phpseclib\Crypt\Common\Keys\PKCS1 as PKCS1;


After, a function, like this:

    public function Generate($password) {
        $rsa = new RSA();
        $rsa->load("...");//Here can put XML or PEM Private Key
        $rsa->setPassword($password);
        PKCS1::setEncryptionAlgorithm('DES-EDE3-CBC');//You can use any available
        $privatekey = $rsa->getPrivateKey("PKCS1");
        return $privatekey;
    }

No hay comentarios:

Publicar un comentario