2017-01-02 122 views
1

openssl_public_encrypt PHP函數,我想獲得下面的代碼的等效紅寶石:相當於紅寶石

$key = '-----BEGIN PUBLIC KEY----- 
some public key 
-----END PUBLIC KEY-----'; 

$cc_number = '4242424242424242'; 
openssl_public_encrypt($cc_number, $cc_number_encrypted, $key); 
echo base64_encode($cc_number_encrypted); 

我想:

pkey = '-----BEGIN PUBLIC KEY----- 
some public key 
-----END PUBLIC KEY-----' 

cc = '4242424242424242' 
key = OpenSSL::PKey::RSA.new(pkey) 
puts Base64.encode64(key.public_encrypt(cc)) 

,但它不工作。 如何在Ruby中編寫這段PHP代碼?

回答