16

I have been instructed to write an application that takes some data then encrypts it with an RSA public key.

It needs to be "RSA encryption":

Which encryption cipher is RSA meant to use as standard?

var key = "TUlHZE1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTEFEQ0Jod0tCZ1FDbVFiTWc3SWRpeHVmYWEwcDd2ODVLVytmUnVlZ216UUhibnNoWjhmbXlTQW9MMXRFVzAyNEZKVFlSTFZxN0VsV2p1R0U4aHQ3RmJjN1NURWpxZVViWU5xdnRiVWN6UFZYSE5FdStYRUVndGszazlFNXVQWG0wVzRIc3RtK0FhRXcyMmxxb2lFNGlrT1QzZzdPRXNHSVFCMVNlSlRtVTE1eFBBZ3M3SXRjTVFRSUJFUT09";

var data = "Xa21dr";
5
  • 4
    Your question doesn't explain what you've done to try and solve the problem; it currently reads like a request for code. Please share your attempted implementation and explain how it fails to meet your requirements. Commented Jul 16, 2013 at 19:57
  • 1
    First of all, there seems to be little reason to perform double base 64 encoding on a BER encoded PKCS#1 public key. (I was wondering why the data did not start with an uppercase M :) Commented Jul 16, 2013 at 20:24
  • 1
    @DuncanJones i am not asking for "code" if you read what i am asking you will understand my question i am asking HOW what is the fundamentals of encrypting a RSA public key and some data together because i cant find anything that works. Commented Jul 17, 2013 at 7:38
  • 1
    @owlstead yes that seems correct i have decoded the key before with base64 that will give you that for example - MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQCmQbMg7Idixufaa0p7v85KW+fRuegmzQHbnshZ8fmySAoL1tEW024FJTYRLVq7ElWjuGE8ht7Fbc7STEjqeUbYNqvtbUczPVXHNEu+XEEgtk3k9E5uPXm0W4Hstm+AaEw22lqoiE4ikOT3g7OEsGIQB1SeJTmU15xPAgs7ItcMQQIBEQ== but apparently the key must stay intact how its received then encrypt the data with it bytes[] to be sent out. Commented Jul 17, 2013 at 7:41
  • 1
    you obvious don't know how RSA works then, nevermind this has all been sorted now! Commented Jul 25, 2013 at 21:01

2 Answers 2

23

Found the answer -

RSA Encryption standard uses PKCS #1

Best library to use is pidCrypt, nothing else worked for me!

pidCrypt https://sourceforge.net/projects/pidcrypt/

Forge https://github.com/digitalbazaar/forge

They failed to let me know that the RSA Public Key was meant to be base64 decoded also before encrypting the DATA before posting.

Sign up to request clarification or add additional context in comments.

6 Comments

What is the format of the encrypted data? Is it also base 64?
pidder is no longer online?
@Toubey looks to be still online to me just checked their website - pidder.com/pidcrypt - still accessible. you can download from source forge directly too - sourceforge.net/projects/pidcrypt
The project is no longer maintained. Also @whitedeath - can you clarify whether it implemented PKCS#1 v1.5 (which is understand is easily attackable since 1998) or PKCS#1 v2.2 (RSA with Optimal Asymmetric Encryption Padding). For those reasons and ease of use i went with forge, which also is a pretty active project on github.
@Philzen No idea which PKCS v is packaged with pidCrypt you will need to download the source and take a look (i needed PKCS #1 so went with pidCrypt as it worked perfectly for my needs).
|
13

You may be interested in trying out forge (it does RSA and more). There are lots of examples on the README:

https://github.com/digitalbazaar/forge

2 Comments

thanks, pidCrypt is working perfectly but will take a look. pidCrypt offers not just RSA too.
forge is very nice. I had a little trouble getting it started, so I created the demo here: digitalbazaar.github.io/forge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.