16

Can anyone please help me with this - I have been instructed to write an application that takes some data then encrypts it with an RSA public key.

It 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";
yeah22
  • 308
  • 3
  • 11
null
  • 2,499
  • 4
  • 23
  • 40
  • 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. – null 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. – null Jul 17 '13 at 07:41
  • 1
    you obvious don't know how RSA works then, nevermind this has all been sorted now! – null Jul 25 '13 at 21:01

2 Answers2

23

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.

null
  • 2,499
  • 4
  • 23
  • 40
  • 12
    the last line in your response saved me a lot of time. – Houcem Berrayana Nov 05 '13 at 11:04
  • thanks, if you found this useful then please mark the answer as useful :) – null Jan 25 '14 at 13:14
  • 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/ – null May 12 '15 at 14:09
  • Thanks @whitedeath, apparently there was something wrong with by the time i checked it. – Toubey May 13 '15 at 14:34
  • 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). – null 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
12

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,068
  • 14
  • 17
  • thanks, pidCrypt is working perfectly but will take a look. pidCrypt offers not just RSA too. – null Jul 29 '13 at 16:37
  • 3
    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