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";
K-G
  • 2,799
  • 4
  • 26
  • 42
  • 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. – Duncan Jones Jul 16 '13 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` :) – Maarten Bodewes Jul 16 '13 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. – K-G Jul 17 '13 at 07: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. – K-G Jul 17 '13 at 07:41
  • 1
    you obvious don't know how RSA works then, nevermind this has all been sorted now! – K-G Jul 25 '13 at 21:01

2 Answers2

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.

K-G
  • 2,799
  • 4
  • 26
  • 42
  • What is the format of the encrypted data? Is it also base 64? – Tarion Feb 06 '14 at 01:07
  • pidder is no longer online? – Toubey Apr 28 '15 at 12:49
  • @Toubey looks to be still online to me just checked their website - https://www.pidder.com/pidcrypt/ - still accessible. you can download from source forge directly too - http://sourceforge.net/projects/pidcrypt/ – K-G May 12 '15 at 14:09
  • 1
    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 Jan 26 '16 at 12:41
  • @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). – K-G Jan 27 '16 at 12:53
  • Note: pidCrypt is licensed under GPL (thus, your software must legally also be licensed under GPL if you use the library) – yeah22 Jan 02 '22 at 19:04
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

dlongley
  • 2,078
  • 14
  • 17
  • thanks, pidCrypt is working perfectly but will take a look. pidCrypt offers not just RSA too. – K-G Jul 29 '13 at 16:37
  • 4
    forge is very nice. I had a little trouble getting it started, so I created the demo here: http://digitalbazaar.github.io/forge/ – Todd Horst Aug 26 '14 at 23:15