15
votes

can anyone please help me with this, i have been instructed to write an application that takes some DATA then Encrypts it with a RSA Public Key and apparently needs to be RSA Encryption(i have never heard or seen this before)?

Which encryption cipher is RSA meant to use as standard?

var key = "TUlHZE1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTEFEQ0Jod0tCZ1FDbVFiTWc3SWRpeHVmYWEwcDd2ODVLVytmUnVlZ216UUhibnNoWjhmbXlTQW9MMXRFVzAyNEZKVFlSTFZxN0VsV2p1R0U4aHQ3RmJjN1NURWpxZVViWU5xdnRiVWN6UFZYSE5FdStYRUVndGszazlFNXVQWG0wVzRIc3RtK0FhRXcyMmxxb2lFNGlrT1QzZzdPRXNHSVFCMVNlSlRtVTE1eFBBZ3M3SXRjTVFRSUJFUT09";

var data = "Xa21dr";
2
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. - Duncan Jones
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 :) - Maarten Bodewes
@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. - null
@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. - null
you obvious don't know how RSA works then, nevermind this has all been sorted now! - null

2 Answers

22
votes

Never mind found the answer myself!

RSA Encryption standard uses PKCS #1

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

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

the idiots on the other end failed to let me know that that RSA Public Key was meant to be base64 decoded too before encrypting the DATA before sending.

12
votes

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