How to remove padding after RSA decryption??

Hello,
I am testing my host apps ability to read public key that was saved in file after being exported from smart card where it was generated.
I have successfully used the private key on card to encrypt a small piece of data and the cryptogram is returned to the host.
On host side I retrieve public key from file and decrypt ciphertext
The on-card alg for Cipher is declared as follows-
RSAcipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, true);and in the host app
Cipher rsaCipher = Cipher.getInstance("RSA","BC");I can see from what is returned from
byte[] decrypted = rsaCipher.doFinal(this.encryptedData);that the correct data is being returned, but is is padded by
01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFF00How do I know where the padding ends and the plaintext begins?
Can anyone help me with this?
Thanks in advance,
Ann

Hi!
I have the same problem like you.
But my problem is that i don,t know how to move the key across. I manege to create a pair of keys public and private using RSA Algorithm.
privateKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE,KeyBuilder.LENGTH_RSA_512,false);
        publicKey = KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC,KeyBuilder.LENGTH_RSA_512,true);
                    // KeyPair creation
                    if(keyPair == null){
                        keyPair = new KeyPair(KeyPair.ALG_RSA, (short)publicKey.getSize());
                    // starts key generation process
                    keyPair.genKeyPair();
                  publicKey = keyPair.getPublic();
                    privateKey = keyPair.getPrivate();
                     cipher = Cipher.getInstance(ALG_RSA_NO_PAD, false );then i send the modulus and exponent part of the public key to host
             byte    keyElement = (byte)(apduBuffer[ISO7816.OFFSET_P2] & 0xFF);
                 // check correct type (modulus or exponent)
                 if((keyElement != 0x00) && (keyElement != 0x01))
                     ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
                 // check elements request
                 if(keyElement == 0) {
                     // retrieve modulus
                     apduBuffer[0] = (byte)((RSAPublicKey)publicKey).getModulus(apduBuffer, (short)1);
                 } else
                     // retrieve exponent
                    apduBuffer[0] = (byte)((RSAPublicKey)publicKey).getExponent(apduBuffer, (short)1);
                 // send the key element
                 apdu.setOutgoingAndSend((short)0, (short)((apduBuffer[0] & 0xFF) + 1));I decrypt the data as follow in the card
      byte[] apduBuffer = apdu.getBuffer();
      if(!privateKey.isInitialized())
                        ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
      cipher.init(privateKey,Cipher.MODE_DECRYPT);
      apdu.setIncomingAndReceive();
     cipher.doFinal(apduBuffer, (short)ISO7816.OFFSET_CDATA, (short)(apduBuffer[ISO7816.OFFSET_LC] & 0xFF), apduBuffer, (short)0);
    apdu.setOutgoingAndSend((short)0, (short)(KeyBuilder.LENGTH_RSA_512/8));
   in host i encrypt data as follow
// Note modulus and exponent are arrays of bytes from the card
    BigInteger modulus = new BigInteger(1,modulus);
    BigInteger exponent =new BigInteger(1,exponent);
    cipher = Cipher.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(modulus,exponent);
keyFactory = KeyFactory.getInstance("RSA");
pubKey = keyFactory.generatePublic(pubKeySpec);
cipher.init(Cipher.ENCRYPT_MODE,pubKey);
byte[] p = cipher.doFinal(data);

Similar Messages

  • How to remove space after paragrph in pages on ipad

    Can't figure out how to remove space after each paragraph in Pages for Ipad

    Settings > General > International > Region Format
    Set it to your country to format numbers and dates in the way your country does.

  • How to remove errors after running sapf190

    Hi everyone
    Can anyone please guide me what procedure do i have to follow if i found differences in one of the gls after running the report sapf190. The report shows me difference in one of the Gls with debit index, debit master not matching credit index and credit total master not matching. But the programme dont tells me how to remove this error. Your kind help will be really appreciated.
    Regards

    RESOLVED

  • How to remove zero after decimal point.

    hi friends
    how to remove the zero after decimal points.
    example :
    123.450 -- if print only 123.45
    45.600  - 45.6
    any body help me.
    thanks
    pauldhama

    go through this example
    it may help u
    DATA: T(14) VALUE ' abcdefghij',
    STRING LIKE T,
    STR(6) VALUE 'ghijkl'.
    STRING = T.
    WRITE STRING.
    SHIFT STRING LEFT DELETING LEADING SPACE (or use 0 to detete 0).
    WRITE / STRING.
    STRING = T.
    SHIFT STRING RIGHT DELETING TRAILING STR or 0.
    WRITE / STRING.
    Output:
        abcdefghij
    abcdefghij
            abcdef

  • How to remove modules after installation

    Hi;
    Picture this please, u are making r11 installation and while u are making installation on Lisence Produts step you click Finance,Logistic etc.. modules and then you complite your installation wihtout any problem.
    After installation functional person comes and start to make their setup on EBS for all modules which is installed... After sometimes they notice The client doesnt need Logistic module, client side give wrong information about modules and person who made installation of EBS click Logistic wiht client wrong information.
    The question is:
    1. We can remove modules after installation?
    2. Is it better way to make new installation (Imagine fonctional is already work more than 2 months,if we make new instalaltion its mean we lose 2 months)
    3. If we can remove it can affect other module setups?
    Thanks for advice
    Regards
    Helios

    Hi,
    1. We can remove modules after installation?No.
    2. Is it better way to make new installation (Imagine fonctional is already work more than 2 months,if we make new instalaltion its mean we lose 2 months)It would be making a fresh installation or restoring from a backup to a point before this module was licensed.
    3. If we can remove it can affect other module setups?There is no direct and supported way to achieve this. However, you may log a SR and see if Oracle can help about this.
    Regards,
    Hussein

  • How to encode/pad an RSA-Encrypted Triple-DES Key

    Similar to this guy's problem: http://forum.java.sun.com/thread.jspa?messageID=3332692&#3332692
    I am having an issue along the same lines... I'm writing a java client that is dealing with a C++ agent, which is expecting an encrypted TripleDES key. However when I create a DesEDE key, then encrypt it using a public RSA key, I am only sending 24 bytes, where the C++ code is expecting 32.
    Luckily, I DO have a C++ client that is doing what I need to do, so I'm investigating exactly how they're doing with the padding/encoding in order to fix my problem. But it's using the crypto 5.1 library (crypto++ maybe) and its not the most readable code.
    If anyone's done anything similar, I'd appreciate any tips/advice for how you dealt with it.
    tOm

    32/24 == 4/3 == the expansion ration converting bytes to Base64.
    Is this a possibility?

  • Dv7-1464nr How to remove keyboard after a spill ?

    A friend had a spill all over the keyboard. Now the laptop won't boot. How do I remove the keyboard? in the bottom there are like 6 m2.5x12 screws one of marked keyboard, about 18 m2.5x3. 3 of are under dvd ?? 

    Stabilize, not warp stabilize the shot, make your corrections on a separate layer, then re-introduce the motion to the shot and add it to the new layer. Here's the basic technique on a completely different type of shot.
    If there is a big parallax shift in your shot then this technique may not work. If it doesn't work then show is the shot and we can make some other suggestions.

  • How to remove padding from lightbox

    There seems to be a natural amount of padding when making a lightbox.  How can I edit that amount of padding so that I may have a full bleed lightbox?

    You can see 3 containers.  Starting from the furthers outside: document/page (gray), Lightbox background(lightgray), lightbox container(black).  If I widen the lightbox container(black) the lightbox background scales to keep about 20ish pixels of padding.  This becomes extra problematic because if the lightbox floods out of the document then it creates errors. I would like the image to bleed from left to right with no padding; thus, no margin/padding just directly touching the page edge.  

  • How to remove CS3 after upgrade to CS4

    What is the best way to remove all my CS3 suite after I upgraded to CS4 Suite? Thanks.

    As I no longer require CS3 on my Mac after upgrading to CS4 and waiting for the required plugins to be available I have successfully uninstalled CS3 using the Adobe CS3 Creative Suite uninstaller.
    NOTE: please make a copy of the 'Adobe Unit Types.osax' found Macintosh HD/Library/ScriptingAdditions/Adobe Unit Types.osax
    At home did this without making a backup of the 'Adobe Unit Types.osax', so when I launched Photoshop CS4 it suffered from the "Error: "One or more files in the Adobe Application Support folder.."
    At work I did this with making a copy of 'Adobe Unit Types.osax', place it back after the uninstall of CS3... and presto so far so good.
    for the 'Error: "One or more files in the Adobe Application Support folder... are missing' when you start Photoshop CS4 (Mac OS)" read here:
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb407726
    sorry if this has already been posted, I could not see this anywhere.

  • How to remove app after upgrade to os 6 on iphone 4s

    I cannot get the apps to show the removal x to get rid of an app after upgradeing to the new os 6 on my iphone 4s

    DELETING APPS
    Touch the app and hold your finger down until all the apps start to jiggle. You will see a circled "x" in the upper left corner. Tap it to delete an app. When done press the Home button.
    You cannot delete any pre-installed iOS app.
    If there is No 'X' on any apps you have Downloaded... then check in Restrictions... Settings > General > Restrictions > Deleting Apps  =  Off / On
    If the app is in iTunes, then you delete the app in iTunes (Select the App and Press Delete on your Keyboard). If you then sync with your iDevice, the app will also be deleted from your iDevice.

  • How to remove spaces after description.

    hi all,
    i need to supress spaces after writing material description and i want to keep comma after description.
    but it displays comma after field length (i e after  40 chars).But i need to keep comma after description it self.
    example like this.
    GR Number- 4900000400,
    Batch Number-            ,
    Material number- P0001016,
    Material description- Returnable Pallet,
    Vendor:            ,
    GR Date: 16.02.2010 ;
    Not Like this...
    GR Number- 4900000400 ,
    Batch Number-            ,
    Material number- P0001016           ,
    Material description- Returnable Pallet                        ,
    Vendor:            ,
    GR Date: 16.02.2010 ;
    after  posting message the comma comes after desc in both the cases...but it wont in SAP
    Appriciate your help.

    Hi,
       Use condense statement.
    Regards,
    Srini.

  • How to remove itunes after starting

    I know that you can manually stop  ITUNES with cutoff,  can you or how do you delete the playing of ITUNES without manually stopping the songs?

    Just install 11; it'll automatically overwrite the older version.
    (78546)

  • How to remove override after importation of XML automatically

    Does anyone know of the best way to automate the removeoverride concept after importation of XML into an InDesign template without manually threading to a new page.
    I am trying to write a batch program that will create multiple XML files and then generate an InDesign document for each XML file from a predefined InDesign template file that is already mapped to the XML structure.

    RESOLVED

  • How to Remove Margins after Convert to PDF

    Hi yall,
    I converted my document to PDF. The PDF displays fine full bleed without margins. However when I print the pdf, margins appear! What is the best way to remove them?
    Thank you!

    Margins are white space between the edge of the page and the text. To say you don't want the margins to appear suggests that you want text (or whatever your page is made up from) to print up to the edge of the page. I doubt that's what you want, so a clearer explanation is needed. And don't forget the version number this time.

  • How to remove separator after setting featuresOff="viewMenu formatMenu"

    For one of our collection we had to remove the menus 'Action', 'View' and 'Format'.
    It works fine with featuresOff="viewMenu formatMenu" and actionsMenuRendered="false".
    Now we have the requirement also to remove the leading separator.
    Any proposals, suggestions ?
    Thanks Ingrid

    check the comments
    https://blogs.oracle.com/aramamoo/entry/what_does_featureoff_attribute_do
    it's not possible to remove separators.
    you can create your own menu..
    <f:facet name="secondaryToolbar">
    <af:toolbar id="t1">
    <af:commandToolbarButton ...
    <f:facet name="popup">
    <af:menu text=" " id="m2">
    <af:commandMenuItem ...
    Edited by: Puthanampatti on Feb 21, 2013 7:07 AM

Maybe you are looking for

  • How to print input boxes

    I need to print a grant proposal that has several input boxes that are filled beyond the viewable area.  When I print the document, Not all the inputed text is printed.  I have tried using a smaller font but can't get it small enough to view all the

  • How to get web pages opening within pages?

    Just wondering how this is done or implemented. I visited and researcehd several websites a while ago and observed that pages were opening in pages instead of loading a new page. For example: You go to a web page, the links are all above under the pa

  • Keyboard selection of user on login window

    Since using Mountain Lion, when all users are logged out and the Mac goes to sleep, on wake up, I am no more able to select the user on the login window using the (bluetooth) keyboard. However, if I click with the mouse on one of the users icon, sele

  • Charges associated with switching from Family to Individual Plans

    Is there any kind of penalty charge  for switching from a family plan to an individual plan when it is the secondary line that is being removed and the secondary lines' contract is complete?

  • What the Hell is Application Server 10g R2

    Hello Experts....I am using Application Server 10g R2 on Windows Server 2003..In the Morning Everything(Especially Reports) Works fine...but in Evening i think it the Report Server get tired...it take too much time to run even simple Report..What the