TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


Forums >


RSA cross platform

Ashikali Ashikali

2/20/2009 1:38:00 PM

I am using Debian OS and ruby 1.8 version .

I have attached .pfx certificate file . Which was created using openssl
command as follows ,
# create a file containing key and self-signed certificate
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

# export mycert.pem as PKCS#12 file, mycert.pfx
openssl pkcs12 -export -out mycert.pfx -in mycert.pem -name "My Certificate"

Using the openssl library in ruby I am able to do encryption and
decryption . Apart from this . I encrypted data in C#( windows ) using
this .pfx file . The c# coding is ,
public string GetEncryptedText(string PlainStringToEncrypt)


X509Certificate2 x509_2 = new X509Certificate2("C:/mycert.pfx",

X509Store store = new X509Store(StoreLocation.CurrentUser);


foreach (X509Certificate2 cert in store.Certificates)




x509_2 = cert;




if (x509_2 == null)

throw new Exception("No Certificate could be found in
name " + DigitalCertificateName);



string PlainString = PlainStringToEncrypt.Trim();

byte[] cipherbytes =

RSACryptoServiceProvider rsa =

byte[] cipher = rsa.Encrypt(cipherbytes, false);

return Convert.ToBase64String(cipher);


catch (Exception e)


throw e;


Encrypted Data is :

This encrypted data was created in C#(windows) using above code but
mycert.pfx was created in linux machine . Now I want to do
decryption in ruby linux .
I followed following decryption methods in ruby ,
create the privatekey.pem using openssl command is ,
openssl pkcs12 -in mycert.pfx -out private.pem -nodes
#give the password as "paymate"

ruby coding to decrypting is ,
private_key = OpenSSL::PKey::RSA.new(File.read("./private.pem"))

#But it through me error

kindly provide me any other solution in ruby


Posted via http://www.ruby-....