Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > RSA cross platform

Reply
Thread Tools

RSA cross platform

 
 
Ashikali Ashikali
Guest
Posts: n/a
 
      02-20-2009


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",
"paymate",X509KeyStorageFlags.MachineKeySet);

X509Store store = new X509Store(StoreLocation.CurrentUser);

store.Open(OpenFlags.ReadWrite);

foreach (X509Certificate2 cert in store.Certificates)

{

if
(cert.SubjectName.Name.Contains(DigitalCertificate Name))

{

x509_2 = cert;

break;

}

}



if (x509_2 == null)

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

try

{

string PlainString = PlainStringToEncrypt.Trim();

byte[] cipherbytes =
ASCIIEncoding.ASCII.GetBytes(PlainString);

RSACryptoServiceProvider rsa =
(RSACryptoServiceProvider)x509_2.PublicKey.Key;

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

return Convert.ToBase64String(cipher);

}

catch (Exception e)

{

throw e;

}

}
Encrypted Data is :
"qLH9NZcxGL2vwuee4uryO8xphinBdE7XWttQmWfLhmOXVv5kF HW3JHTR0MiDfvONcHtPtvzKaCvgKlThd2XoNQm3K0EfRMKyokv DSWITQjTjHMOKyNGRCknsfm1dTrlZKU5eYNV+Qzn+MDdJ2gAb4 vldbjFchgMFs2Qb2RJz3f4="

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:Key::RSA.new(File.read("./private.pem"))
private_key.private_decrypt(Base64.decode64("qLH9N ZcxGL2vwuee4uryO8xphinBdE7XWttQmWfLhmOXVv5kFHW3JHT R0MiDfvONcHtPtvzKaCvgKlThd2XoNQm3K0EfRMKyokvDSWITQ jTjHMOKyNGRCknsfm1dTrlZKU5eYNV+Qzn+MDdJ2gAb4vldbjF chgMFs2Qb2RJz3f4="
))

#But it through me error

kindly provide me any other solution in ruby

Attachments:
http://www.ruby-forum.com/attachment/3325/mycert.pfx

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

 
Reply With Quote
 
 
 
 
Ashikali Ashikali
Guest
Posts: n/a
 
      07-09-2009

I have wrongly used the key .

use instead of private.pem , what you have created key file using
openssl .

But it has been working fine . No problem at all .

Above steps are useful for doing encryption in windows and decryption in
Linux especially on UNIX based opearating systems .

cheers,
ashikali .
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ashikali Ashikali
Guest
Posts: n/a
 
      07-09-2009
Ashikali Ashikali wrote:
>
> I have wrongly used the key .
>
> use instead of private.pem , what you have created key file using
> openssl .
>
> But it has been working fine . No problem at all .
>
> Above steps are useful for doing encryption in windows and decryption in
> Linux especially on UNIX based opearating systems .
>
> cheers,
> ashikali .


Yeah, It is working fine

With regards,
Veeramani. N
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ashikali Ashikali
Guest
Posts: n/a
 
      07-09-2009



Now RSA is possible in cross platform .

cheers,
vetrivel
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting Win98 platform to WinXP Pro platform dancesportboston Wireless Networking 1 09-02-2006 10:36 PM
does java program run on 64-bit platform as fast as on 32-bit platform jcc Java 15 05-12-2006 08:52 AM
New Windows platform and 64 bit platform =?Utf-8?B?T21hciBLaGFu?= Windows 64bit 12 11-30-2005 11:05 PM
Implementing .net RSA on the server *and* JavaScript RSA on the client gg ASP .Net 0 11-18-2004 10:29 PM
How can I convert the C6.0 program of OS/2 platform TO a program in windows2000/xp platform? Coca C Programming 15 01-14-2004 04:44 PM



Advertisments