phpseclib\Crypt\Common\PKCS1::wrapPrivateKey PHP Method

wrapPrivateKey() static public method

Wrap a private key appropriately
static public wrapPrivateKey ( string $key, string $type, string $password ) : string
$key string
$type string
$password string
return string
    static function wrapPrivateKey($key, $type, $password)
    {
        if (empty($password) || !is_string($password)) {
            return "-----BEGIN {$type} PRIVATE KEY-----\r\n" . chunk_split(Base64::encode($key), 64) . "-----END {$type} PRIVATE KEY-----";
        }
        $cipher = self::getEncryptionObject(self::$defaultEncryptionAlgorithm);
        $iv = Random::string($cipher->getBlockLength() >> 3);
        $cipher->setKey(self::generateSymmetricKey($password, $iv, $cipher->getKeyLength() >> 3));
        $cipher->setIV($iv);
        $iv = strtoupper(Hex::encode($iv));
        return "-----BEGIN {$type} PRIVATE KEY-----\r\n" . "Proc-Type: 4,ENCRYPTED\r\n" . "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",{$iv}\r\n" . "\r\n" . chunk_split(Base64::encode($cipher->encrypt($key)), 64) . "-----END {$type} PRIVATE KEY-----";
    }