Lightweight RSA implementation (lighter than BouncyCastle)?

I wonder if by chance there is a more lightweight implementation of RSA for MIDP than the one provided by BouncyCastle? I managed to use the BouncyCastle classes, but RSA+AES encryption together make up for more than 16KB of the jar-File. The bulk of it seems to stem from the BigInteger class. Perhaps by implementing only the operations that are relevant to RSA it would be possible to arrive at a shorter solution?
If anybody knows of a smaller implementation, it would be great to hear about it!
Many thanks in advance!

I've done this helping another ThoughtWorker migrate from Cryptix to BC. It's not an easy task, especially seeing that Cryptix did some really "non-standard" stuff early on.
It does work (or at least I believe it does work, as I haven't been asked for assistance recently ;-) ), and you should be able to just convert the keys by using the bits you need.
The other thing that's worth being careful about is that the Cryptix code allowed data encrypted with the RSA keys to be of any mode, including some really busted padding called "ZerosAndOnes". (Don't ask, it's too stupid for words).
Make sure your encrypted data can be successfully decrypted, and what the various modes are, because if you convert all your code, then you might have difficulties later on trying to decrypt it.
The first thing I did was to create some code that was a compatibility mode and used the light-weight API's to deal with the transformations. After all the Cryptix code has been removed, it will be a trivial matter to implement the bits that are really needed using the JCE code (if desired).
Why use the lw-api ? Well, I needed to create a new padding, and doing that with the JCE (and then resigning it) was going to be a real pain. And, all the JCE code uses the LW code underneath anyway, so I knew there wasn't going to be a compatibility problem.
So, after all that waffle, it should work, but just watch out for how people used the Cryptix RSA keys for encrypting the data. Cryptix didn't check if people were doing dumb things, and that may be the case.
Cheers,
-- jon

Similar Messages

  • RSA implementation basics ...

    Hi,
    Iam totally new to the Java Card programming. I want to find out how is RSA implemented. Now if I need to get some information from card (eg. serial number) and check the same. How do I implement the same using the Host and Smart Card.
    Any light on the same would be appreciated. Also, if anyone has example of implementation of RSA between Host and Smart card would be appreciated (in Delphi and Java) ...
    Thanks

    Hi,
    I have written a code based on a sample. The program has a client which accepts a string at frontend and sends the information to be encrypted at card, then writes the encrypted information to the card. To decrypt the same, there is an option at the frontend to read the string from card, so the program, gets the string from the card (in encrypted form), then sends the string to card decrypt the same. Iam getting an Techincal error (error 38) while decrypting. Can you please help? I need a solution immediately. I been trying to work on the same for last few days.
    I have pasted the code below for reference. Appreciate if some one could respond quickly.
    package rsa_encrypt_decrypt;
    import javacard.framework.*;
    import javacard.security.*;
    import javacardx.crypto.Cipher;
    Host Call:
    iopCard.SendCardAPDU(0x00,0xAA,0x02,P2,iArray,iArray.length);
    Card Applet:
    public class RSAEncryptDecrypt extends javacard.framework.Applet
         // This applet is designed to respond to the following
         // class of instructions.
         final static byte GETSET_CLA = (byte) 0x85;
         final static byte CRYPT_CLA = (byte) 0x00;
         // Instruction set for SimpleString
         final static byte SET = (byte)0x10;
         final static byte GET = (byte)0x20;
         final static byte SELECT = (byte) 0xA4;
    // This buffer contains the string data on the card
         byte TheBuffer[];     
         //globals
         RSAPrivateCrtKey rsa_PrivateCrtKey;
         RSAPublicKey rsa_PublicKey;
         KeyPair rsa_KeyPair;
         Cipher cipherRSA;
         final short dataOffset = (short) ISO7816.OFFSET_CDATA;
         //constructor
         private HandsonRSAEncryptDecrypt(byte bArray[], short bOffset, byte bLength)
         TheBuffer = new byte[100];
         //generate own rsa_keypair
    rsa_KeyPair = new KeyPair( KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_1024 );
    rsa_KeyPair.genKeyPair();
              rsa_PublicKey = (RSAPublicKey) rsa_KeyPair.getPublic();
              rsa_PrivateCrtKey = (RSAPrivateCrtKey) rsa_KeyPair.getPrivate();
              cipherRSA = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
              register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         //install
         public static void install(byte bArray[], short bOffset, byte bLength)
              new HandsonRSAEncryptDecrypt(bArray, bOffset, bLength);
         public void process(APDU apdu)
              if (selectingApplet())
                   return;
              byte[] buf = apdu.getBuffer();
              byte cla = buf[ISO7816.OFFSET_CLA];
              byte ins = buf[ISO7816.OFFSET_INS];
              if ((buf[ISO7816.OFFSET_CLA] != 0) && (buf[ISO7816.OFFSET_CLA] != GETSET_CLA)) ISOException.throwIt (ISO7816.SW_CLA_NOT_SUPPORTED);
              if ((buf[ISO7816.OFFSET_INS] != (byte) (0xAA)) && (buf[ISO7816.OFFSET_INS] != (byte) (0x10)) && (buf[ISO7816.OFFSET_INS] != (byte) (0x20))) ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);
              switch (cla)
                   case GETSET_CLA:
                        switch (ins)
                             case SET:
                                  SetString(apdu);
                                  break;
                             case GET:
                                  GetString(apdu);
                                  break;
                   case CRYPT_CLA:
                        switch (buf[ISO7816.OFFSET_P1])
                             case (byte) 0x01:
                                  encryptRSA(apdu);
                                  return;
                             case (byte) 0x02:
                                  decryptRSA(apdu);
                                  return;
         private void encryptRSA(APDU apdu)
              byte a[] = apdu.getBuffer();
              short byteRead = (short) (apdu.setIncomingAndReceive());
              cipherRSA.init(rsa_PrivateCrtKey, Cipher.MODE_ENCRYPT);
              short cyphertext = cipherRSA.doFinal(a, (short) dataOffset, byteRead, a, (short) dataOffset);
              // Send results
              apdu.setOutgoing();
              apdu.setOutgoingLength((short) cyphertext);
              apdu.sendBytesLong(a, (short) dataOffset, (short) cyphertext);
              //SetString(apdu);
         private void decryptRSA(APDU apdu)
              byte a[] = apdu.getBuffer();
              short byteRead = (short) (apdu.setIncomingAndReceive());
              cipherRSA.init(rsa_PublicKey, Cipher.MODE_DECRYPT);
              cipherRSA.doFinal(a, (short) dataOffset, byteRead, a, (short) dataOffset);
              // Send results
              apdu.setOutgoing();
              apdu.setOutgoingLength((short) 24);
              apdu.sendBytesLong(a, (short) dataOffset, (short) 24);
         // SetString stores the string on the card.
         private void SetString(APDU apdu) {
              byte buffer[] = apdu.getBuffer();
              byte size = (byte)(apdu.setIncomingAndReceive());
              byte index;
              // Store the length of the string and the string itself
              TheBuffer[0] = size;
              for (index = 0; index < size; index++)
                   TheBuffer[(byte)(index + 1)] = buffer[(byte)(ISO7816.OFFSET_CDATA + index)];
              return;
         //     1. Client sends a GetString APDU with a length of 0
         //     2. Card responds with a Status Word of 0x62YY, where YY is the length
         //          of the string (in hex).
         //     3. The client sends its GetString APDU again, but this time with the
         //          correct length.
         private void GetString(APDU apdu) {
              byte buffer[] = apdu.getBuffer();
              byte numBytes = buffer[ISO7816.OFFSET_LC];
              if (numBytes == (byte)0) {
                   ISOException.throwIt((short)(0x6200 + TheBuffer[0]));
              apdu.setOutgoing();
              apdu.setOutgoingLength(numBytes);
              byte index;
              for (index = 0; index <= numBytes; index++)
                   buffer[index] = TheBuffer[(byte)(index + 1)];
              apdu.sendBytes((short)0,(short)numBytes);
              return;
    }

  • Can't access inbox on ios 7 on iPhone 5 (and prior to updating to ios 7) Type face for "Inbox" is lighter than "Sent", "Trash" etc

    I can't open the Inbox on my iPhone 5, this problem existed prior to downloading and installing the latest ios7 and still exists. The text for "Inbox" is lighter than that of "Sent" or "Trash" which can still be opened. If I turn the phone off and then back on Mail opens into the inbox and new mail is there. Asking Siri to open will also show the content of the inbox, however once I go back to Mailbox the option for Inbox will not open again. Any ideas much appreciated!

    Dear Pierre2936,
    when you have set you iPhone for update the iTunes have automatically made a backup which i assume is saved with you on your PC . check if its there ... as far as your device is concern they might have been some issue while updating the firmware and the updation was not completed properly and due the unsuccessful updation your iPhone is stuck in recovery mode. you need to download the complete iPhone 4S iOS 7.0.2
    http://appldnld.apple.com/iOS7/091-9872.20130924.2wc82/iPhone4,1_7.0.2_11A501_Re store.ipsw from this link and restore the device manually.
    You can do this from within iTunes by shift + mouse click the restore button which will give you an opendialogue box to select the iPSW from which you want to update your iPhone now have patience and let the iTunes complete its process and see if this resolves your issue .
    once your device is in working condition restore your backup which you already have on ur PC and you don't have it then your data is lost :-(

  • My InDesign program is printing my placed images lighter than illustrator.

    I am trying to print a colour logo in Indesign with black type on my inkjet printer.  The colours are appearing fine on screen and so is the black but when I print everything is washed out.  I tried just printing a black box and it appears black on screen but in print it is grey.  I have tried changing the preferences Appearance of Black to rich and accurate but that did not make a difference.  Do I need to do anything in color management I am using Indesign CS2.  How can I solve this problem?

    Acrobat worked, thanks for that advice.   I set my Convert to Profile under the Edit Menu to  Color
    Match RGB.  That helped a little bit but it is not printing like the
    pdf.  I would like to get this problem resolved. I normally use
    illustrator most of my work.  But I would like to have InDesign working
    properly as I need it to do other jobs.
    Take Care,
    Jen
    Take Care,
    Jen
    Date: Fri, 14 Aug 2009 14:24:47 -0600
    From: [email protected]
    To: [email protected]
    Subject: My InDesign program is printing my placed images lighter than illustrator.
    Jen,
    This is a problem that you have no time to fool with, correct?
    When printing from InDesign and all looks hopeless, export to PDF and print from the PDF.
    Why?
    I don't know for sure but it seems all printers made recently accept PDF better than straight from InDesign. It could be the printer driver and it could be InDesign but you don't have time to mess with it now. Wait for some free time to sort it out, but for now output to PDF and print from Adobe Reader or Acrobat.
    >

  • Flex security - RSA implementation?

    Hi all,
    i am developing a client server app, the client is a flex app that communicate with a php server with amf protocol.
    I need some security so i think some possible solution:
    1. using https, but with any "web debugging proxy" anyone can decrypt ssl, so this is not a solution
    2. using an rsa implementation, so if someone read the traffic it wont be a problem, but if someone
         deassemble flex client, can access to the client private key and then the security will go away
    Is there some stuff to securize the communication?
    Thank you

    Hi,
    For security purposes, you would store the private key in the card and perform all private key operations there. One approach could be to store a certificate and the corresponding private key in a java card applet and then retrieve the certificate from the card. You could then send a random number (nonce) to the card and ask it to sign the number. The host application can then verify the signature with the public key in the certificate. The host could also verify the certificate against a certificate authority or a known trust chain.
    The hard part is that you will need to implement this in the applet yourself. You can define a set of APDU's that you could send to the card for specific responses. For instance one command to get the certificate and another to sign some arbitrary data. You would also want a way of injecting the keys (this is the simple less secure approach though).
    With certificates you can use the cryptographic properties to verify that you trust the card and if you do not receive a trusted certificate the program can terminate. Also if the signature is not verified then you could exit as well as the card has not proven ownership of the private key.
    Cheers,
    Shane

  • .swf image comes out lighter than the source

    I'm creating a simple animation in AE from a jpeg image. I bring up some text on the image. When I create the .swf file, the background that the text appears on is lighter than the original jpeg in the Safari browser. Since this animation "tiles" into the page with other jpegs sharing the same background image, the light background produced by the .swf stands out from the rest of the page.
    This only seems to appear in the Safari browser under OSX. FireFox doesn't have this problem. However, since I need this to work across all browsers, I need to solve this issue.
    If I make a .mov file instead of a .swf, it also appears lighter than the source.
    In fact, if I simply take a jpeg image and create a 1 frame .swf from it, it comes out lighter than the original. I'm not doing anything to the image (as far as I know) that would make it lighter.
    Any insight to what is causing this problem would be greatly appreciated.

    It's ColorSync and how it is used throughout your system, even if only for on-screen Gamma correction. In so many words: There's nothing you can do about it but to reset your settings and turn it off wherever that is possible. Not on my Mac ATM and not using Safari anyways, but I'm reasonably certain there's an option for using the system color settings somewhere. Depending on how you process the JPEG you may also need to fiddle with the color settings for the Adobe suite. Flash itself is not color profiled, but it will respect embedded proviles by ways of its image loaders that it shares with Photoshop and al lthe other apps. Beyond that I wouldn't get too crazy over it: Color mismatches and shifting alignment are a natural bane of all web development, and even if you get it right on one machine, the next day another user will tell you that it looked crap on his machine in Konqueror on Linux.... More than anything else, webdesign is a matter of using the design to cheat around these limitations, unfortunately. Perhaps you can use a large background Flash file instead of the original JPEG and then put your HTML content onto a separate DIV layer...? ;-)
    Mylenium

  • Exporting slides to Quicktime but the slides are coming out far lighter than the original slides. Am I missing a setting somehwere?

    Exporting slides to Quicktime but the slides are coming out far lighter than the original slides. Am I missing a setting somehwere?

    Update. Uninstalled QT X and installed v7 and the problem is still there.

  • My IP 4500 is printing lighter than the screen image.

    My IP 4500 is printing lighter than the screen image. I've run the cleaning tool and the nozzle check is OK the colour of grass is too yellow and the picture looks washed out. I've used this printer for some years and have had no problems but now I'm stumped. Anybody help?

    Are you sampling all layers in a document in which you have an adjustment layer active?
    -Noel

  • Image in CS4 looks lighter than in CS3?

    I just started to use CS4, set up all of my color preferences and opened up an image. I thought that it looked a little bit lighter than what I remembered so I opened up the same image in CS3 and it does look different. The 3/4 tones to the shadows all appear slightly lighter than in CS3. I checked the soft proofing in CS4 and I found that when I select the Monitor RGB and apply soft proofing, that fixes the issue. But as soon as I try and select any other profile the image appears lighter than the same soft proof in CS3. Any ideas? And yes my monitor is calibrated, I have the Eizo CG 241 and I am using and 8 Core Mac Pro with 18gb ram and running OS 10.5.5.

    Well when I first posted this issue I was looking at a photo, and if you read my first post I said 3/4 tones to shadow. Since then I did some more testing to rule out that the problem wasn't image specific. I thought that the best way to rule that out was to create a new document in both apps, then fill them with 0,0,0. In both CS3 and CS4 the color reads 0,0,0, but when you open up the screen grab in PS the left side is now 18,18,18. So, yes, this image has nothing to do with 3/4 tones, but the point was to show that you can clearly see that left side is lighter than the right. I am not sure that showing a gray ramp would really tell us anything more. I have been using PS since 2.0, and I make my living with it, so I think I have some idea of how PS and color management work. Lundberg02, If you open up the screen grab I posted and the tone on both sides look the same or you think that they are blue, you need to get a better monitor or check your calibration. Also, if you have read all of my post I stated that I also installed CS4 on another machine that already had CS3, and on that machine everything was fine. Today I did a clean OS install on another drive of the 8 Core, then I only installed PS CS3 and CS4. Did the same comparison as before and everything is fine. Obviously I have some conflict with some other software or utility. I installed ColorNavigator, created a new target, calibrated my monitor, saved the file profile, then quit the application. Checked PS again and everything is fine. Previously I had some issues with ColorNavigator not saving my targets, again I thought maybe it was some conflict with some other apps I had on my system, but this time all I had on my OS was PS CS3 & CS4. So I opened up CN again I noticed that the target I just created was gone. When I looked in the display preferences I could see that the profile that CN created was still there. So now I have to try and deal with that issue.
    Thanks,
    Steve

  • Can a class implements more than one interface?

    Hello
    Can a class implements more than one interface?
    Thanks

    Of course, this doesn't mean that it won't be a problem though. If the two interfaces have methods with the same signature, but different return types, you won't be able to implement them together. I.E.
    interface InterfaceA {
      public int doSomething(String myString);
    interface InterfaceB {
      public String doSomething(String myString);
    // Now the classes
    // Gives error "Duplicate method doSomething(String) in type ClassA"
    public class ClassA implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    // Gives error "The return type is incompatible with InterfaceB.doSomething(String)"
    public class ClassB implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
    // Gives error "The return type is incompatible with InterfaceA.doSomething(String)"
    public class ClassC implements InterfaceA, InterfaceB {
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    }

  • The left top corner of my iphone 5 is lighter than the rest of the screen. What should I do?

    I just noticed that the left top corner of the screen is lighter than the rest of the screen. I have turned off the phone but not sure what to do next. Any suggestions? Shall I just take for repair?
    The screen isn't cracked and phone wasn't in contact with water.
    Thanks

    Hello Reni_rex,
    The article linked below provides some useful troubleshooting steps and information that can help get your iPhone working again.
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    Cheers,
    Allen

  • Video set to stop on last frame appears lighter than last frame

    I've got a video set to "stop on the last frame" using the technique described here:
    http://digitalpublishing.tumblr.com/post/6141054971/how-to-make-a-video-stop-at-the-last-f rame-here
    Works great. But whenever I do this, there is a slight darkening when the multi-state object appears at the end. To create the image for the multi-state objects, I opened the video in Photoshop, grabbed the last frame, and saved it as a JPEG.
    Anyone have any ideas? I've tried saving the end image as a PNG, lots of other workarounds, but the problem persists. I've noticed this in other publications I've downloaded also, so I think the problem is widespread.

    great to see this trick evolve in a first-frame-lasf-frame-method, wich I
    thought about,too lately.
    Will post an update in my article next time ii get the chance.
    —Johannes
    (mobil gesendet)
    Am 27.09.2011 15:33 schrieb "KeithGilbert" <[email protected]>:
    KeithGilbert http://forums.adobe.com/people/KeithGilbert created the
    discussion
    "Re: Video set to stop on last frame appears lighter than last frame"
    To view the discussion, visit:
    http://forums.adobe.com/message/3940255#3940255

  • Light Weight JCE Provider with RSA implementation

    Hi all,
    I'm working on an applet that requires RSA encryption, but I have size constraints so I canno tuse the BouncyCastle provider (891 KBs)
    Does anyone know where to find a light weight JCE provider with an implementation of RSA, I've been searching for a while but without any luck!
    Thank you in advance

    You can use the lw-apis from BC and drop the JCE part. The JCE for BC is just a facade to the lw-apis anyway. And if you use the lw-apis you don't have to worry about any signing issues with the applet.
    Cheers,
    --- jon

  • RSA Implementation for SunJCE Provider

    Hello there!
    I just would like to inquire if there are plans/news for the sun developers to include the RSA Algorithm as part of the cryptographic services available in the pre-installed SunJCE Provider? If so, when?
    Thanks.
    Regards,
    Ronron

    Which RSA algorithm are you looking for? BTW Sun has 4
    JCE providers: SUN, SunJCE, SunRsaSign, SunJSSE.I am referring to the SunJCE Provider, which is
    already included in the latest Java 2 SDK, v 1.4
    release. Those 4 providers are from JDK 1.4
    I am looking for the RSA Algorithm for
    encryption/decryption of data. Because I believe that
    it would be very helpful when the SunJCE would include
    the implementation of that algorithm since the
    provider had been pre-installed in the latest Java 2
    SDK.
    Do you have any idea?I believe they still don't want to have any issues with US export restrictions, especially with that little case when someone need to use RSA encryption. So, they let you to use any 3rd part JCE provider. And there is such a good one for free. Look at the BouncyCastle.

  • DVD Movie is "lighter" than the M2v File - ?????

    Hello Board,
    I need help . . . . again!
    I used the NTSC monitor to color and export the my short film and it looked FINE. Many of the scenes were dimmed (darkened Intentionally) intentionally to create and omnious effect.
    I had to take the monitor back but everything seemed fine. I exported the project via Compressor - Best - 90 minute setting.
    I watched the M2V on the computer and it looked great, so I imported the M2V into DVD pro and created a very basic DVD.
    I burned the DVD pro project to DVD using Toast Titanium 6.
    Now here's the twist. When I watched the DVD on TV, the images were significally ligter than in the M2V file and the DVD SP viewer.
    I said ok, let me put the DVD into the computer and see if it looks different on the computer LCD and it did not, it was still lighter.
    I then did a side by side comparison - with the M2V screen up on the left and the Mac DVD player screen up on the right. I went to the same frame in both and behold, the DVD version is noticable ligher. Things that are concealed by Shadow in the M2V can be seen in the DVD version.
    Is it possible that something in the burn process did this. Or could it be that I saved the file a certain way in DVD SP and that did it?
    I don't think it's an issue with Compressor, because why didn;t the M2V file look light on the computer.
    Any insight would be greatly appreciated.
    Thanks,
    Lin

    It's probably not a problem with Toast or DVD SP. It's the same old display and TV calibration issue that many complain about. Try this with Apple's DVD Player -- switch to an NTSC display profile and see what the DVD looks like then. However, the latter is not a "fix," just an example of how display gamma and calibration can affect results.
    I'd suggest that Lin review the following tutorials on color and brightness adjustments:
    http://www.signvideo.com/dv-black-levels-dvd-authoring-mpeg-2-part-1.htm
    http://www.kenstone.net/fcphomepage/video_levelsnattress.html
    You might also find some useful information in the following thread:
    Waymen, "DVDSP 3 adds ten pounds of brightness on formatting!!!" #16, 03:08pm Sep 13, 2005 CDT<small><hr width="75%"><small>If this suggestion helps in any way, a confirmation or acknowledgment would be appreciated, since that would also help others who may be having the same difficulty. Do for others as you would have them help you.<center>Thanks for sharing, Waymen.</center></small>

Maybe you are looking for