Skip to content

Instantly share code, notes, and snippets.

@pupca
Created December 23, 2010 13:20
Show Gist options
  • Save pupca/752963 to your computer and use it in GitHub Desktop.
Save pupca/752963 to your computer and use it in GitHub Desktop.
## php
function CSignature($privatni, $heslo){
$fp = fopen($privatni, "r");
$this->privatni = fread($fp, filesize($privatni));
fclose($fp);
$this->heslo=$heslo;
}
function sign($text){
$pkeyid = openssl_get_privatekey($this->privatni, $this->heslo);
openssl_sign($text, $signature, $pkeyid);
$signature = base64_encode($signature);
openssl_free_key($pkeyid);
return $signature;
}
## ruby
def self.sign(data,private_key, pass)
key4_pem = File.read Rails.root + "cer/#{private_key}"
key4 = OpenSSL::PKey::RSA.new key4_pem, pass
return Base64.encode64(key4.private_encrypt(data))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment