I wrote these two methods in PHP. The first method, get_pubkey, extracts the public key from a certificate (certnew.cer) and the second method, encryptit(info) returns the encrypted information using the public key extracted by the first function. I need to port these 2 functions to their Javascript equivalent. Does anyone know how to do it?
class Assdig
{
private $pubkey;
/* (... )*/
public function get_pubkey()
{
$certificado = __DIR__ . '/certnew.cer';
$fp=fopen($certificado,"r");
$this->pubkey=fread($fp,8192);
fclose($fp);
openssl_get_publickey($this->pubkey);
}
public function encryptit($info)
{
openssl_public_encrypt($info, $infoencrypted, $this->pubkey);
return base64_encode($infoencrypted);
}
}
I imagine you mean javascript code which runs on a local machine or server ? (as opposed to in a webbrowser).
The PHP functions in question are just wrappers around the openssl library. I imagine the easiest method would be to just execute the openssl binary from your js code.
man openssl-pkey lists most of the relevant commands