If i want to  encrypt a message that i send to Java Card applet like DES

What are the steps that i have to do ?? is there something missing??
//set the private key
private byte[] KeyData = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
           0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,0x39, 0x40};
deskey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 
KeyBuilder.LENGTH_DES, false);
deskey.setKey(KeyData, (short)0);
//InData and OutData are two byte variables for the input message and the //Output message
Cipher cipher;
cipher = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD ,false);
cipher.init(deskey, Cipher.MODE_ENCRYPT);
cipher.doFinal((byte[])InData,(short) 0 , (short) InData.length,(byte[]) OutData,(short) 0);
is that correct? or needs something else?
if i set fixed size for Outdata byte i have to do Padding since i choose (ALG_DES_CBC_NOPAD) method??? in order to send the cipher back to host application Thru APDU command??
How big can the cipher become with the key i used if InData are byte[10]
Thanks in advance

I tried too many corrections and i still get unknown error
i tried this code this time
package gr.teiath.netlab.applets;
import javacard.framework.*;
import javacard.security.DESKey;
import javacard.security.KeyBuilder;
import javacardx.crypto.Cipher;
public class MedBooklet extends Applet {
     final static byte MedBooklet_CLA = (byte) 0xB0;
     // PIN relatives
     final static byte PIN_TRY_LIMIT = (byte) 0x03;
     final static byte MAX_PIN_SIZE = (byte) 0x04;
     OwnerPIN pin;
     //DES
     byte keyArray[] = {(byte)0x09,(byte)0x0e,(byte)0x0d,(byte)0x0c,(byte)0x0b,(byte)0x0a,(byte)0x09,(byte)0x08,
               (byte)0x09,(byte)0x0e,(byte)0x0d,(byte)0x0c,(byte)0x0b,(byte)0x0a,(byte)0x09,(byte)0x08,
               (byte)0x09,(byte)0x0e,(byte)0x0d,(byte)0x0c,(byte)0x0b,(byte)0x0a,(byte)0x09,(byte)0x08};
     private byte[] outBuff;
     private short Lc;
     // allocate key object
     DESKey desKey;
     Cipher cipher;
     // Return codes
     final static short SW_VERIFICATION_FAILED = 0x6300;
     // INS commands
     final static byte VERIFY = (byte)0x20;
     final static byte ADDRECENTRY = (byte)0x30;
     final static byte READRECENTRY = (byte)0x40;
     //private RecipeFile recipeFile;
     //private ReferFile referFile;
     private MedBooklet(byte[] bArray, short bOffset, byte bLength) {
          pin = new OwnerPIN(PIN_TRY_LIMIT,MAX_PIN_SIZE);
          pin.update(bArray, bOffset, bLength);
          desKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES,KeyBuilder.LENGTH_DES,false);
          // set key value
          desKey.setKey(keyArray,(short)0x00);                    
          //recipeFile = new RecipeFile();
          //referFile = new ReferFile();
          register();
     public static void install(byte[] bArray, short bOffset, byte bLength) {
          new MedBooklet(bArray,bOffset,bLength);
     public boolean select() {
          if(pin.getTriesRemaining()==0) return false;
          return true;
     public void deselect() {
          pin.reset();
     public void process(APDU apdu) {
          byte[] buffer = apdu.getBuffer();
          if ((buffer[ISO7816.OFFSET_CLA]==0) && (buffer[ISO7816.OFFSET_INS])== (byte) 0xa4) return;
          if (buffer[ISO7816.OFFSET_CLA]!=MedBooklet_CLA)
               ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
          switch (buffer[ISO7816.OFFSET_INS]) {
          case ADDRECENTRY: addrec(apdu);
               return;
          case READRECENTRY: readrec(apdu);
               return;
          case VERIFY: verify(apdu);
               return;
     public void addrec(APDU apdu){
          //byte[] buffer = apdu.getBuffer();
          //byte byteRead = (byte) (apdu.setIncomingAndReceive());
          //if (byteRead==0x1f)
               //recipeFile.newRecord(buffer, ISO7816.OFFSET_CDATA, (short) byteRead);
//           create cipher instance
          cipher = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD,false);
          byte[] buf = apdu.getBuffer();
          Lc = (short) (buf[ISO7816.OFFSET_LC] & 0x00FF);
          //     array storing output buffer
          outBuff = new byte[Lc];
          // initialize cipher
          cipher.init(desKey,Cipher.MODE_ENCRYPT);               
          Lc = cipher.doFinal(buf,(short)ISO7816.OFFSET_CDATA,Lc,outBuff,(short)0x00);
          // set output to be returned with same size of the input
          apdu.setOutgoing();
          apdu.setOutgoingLength(Lc);
          apdu.sendBytesLong(outBuff,(short)0x00,Lc);     
     public void readrec(APDU apdu) {
          byte[] buffer = apdu.getBuffer();
          short le = apdu.setOutgoing();
        apdu.setOutgoingLength( (short) (35) );
        // echo header
        //apdu.sendBytes( (short)0, (short) 5);
        // echo data
       // apdu.sendBytesLong( recipeFile.getRecord() , (short) 0, (short) 35 );
     private void verify(APDU apdu) {
          byte[] buffer = apdu.getBuffer();
          byte byteRead = (byte) (apdu.setIncomingAndReceive());
          if (pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead)== false)
               ISOException.throwIt(SW_VERIFICATION_FAILED);
}I have another Problem When in constructor i try to
cipher = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD,false);I cant veriry the PIN so i always get exit command are there conflicts when are in the same constructor between
pin.update(bArray, bOffset, bLength);
VS
cipher = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD,false);
VS
register();Are there Limitations about "Cref" do i have to send the data to be encrypted no more than byte of 8 hex ?

Similar Messages

  • I have an iphone that I just deactivated (SIM card removed) - I still want to sync with iTunes but keep getting error message that there is no SIM card installed?

    I have an iphone 3GS that I have inactivated as of today. I still wish to sync this phone with iTunes (did a restore as I transferred my data to a new iPhone).  However, iTunes is giving me an error message that there is no SIM card installed in the iPhone I'm attempting to activate.  I've powered off the phone, held the power button & home button until iTunes popped up with restore note.  Re-did the restore (twice) but still coming up with same error message.

    Kind of what I figured.....will I be able to sync to iTunes in future as many times as I want without the SIM card (once it's activated again)?

  • I want to build a website that can send out email automatically using c#

    I want to build a website that can send out email automatically using c# and sql server when a date has reached. I have googled but nothing works.
    http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/using-quartz.html
    I came across this, but I am still unsure what to do. 

    I came across this, but I am still unsure what to do
    http://forums.asp.net/

  • I accidentally linked my wife's phone number with mine. Now I am getting MY text messages that I send to her. It even says my texts are from her. How can I fix it?

    I accidentally linked my wife's phone number with mine. Now I am getting MY text messages that I send to her. It even says my texts are from her. How can I fix it?

    You can't "link" phone numbers but you can, and did add her email address to your iMessage send/receive list.  This often happens when you both use the same Apple ID
    Settings > Messages  > Send & Receive > you can be reached by iMessage at >
    Settings > Messages > Send and Receive > start mew conversations from ?
    You are receiving your own messages because the same email address is on both lists

  • My husband and I both have 4 iphones. I do not receive any text messages that he sends me. He gets mine though.   He sends texts to other iphone users and they get them.  I get text messages from other phones including iphones. Please help.

    My husband and I both have Iphone 4's. I do not receive any text messages that he sends me. He gets mine though.   He sends texts to other iphone users and they get them.  I get text messages from other phones including iphones. Please help.

    Both of yall need to go to settings, meassages, send and recieve, scroll down to start new conversation from, and make sure you have different email addresses with a check mark beside it. Right now sounds like they are the same email addresses.

  • Why do other people get my messages that I send to a specific person

    Why do other people get my messages that I send to a specific person

    They may have all signed into the same ID for iMessage when they updated their devices.  To fix this you have a couple of choices:
    On all but one of the devices go to Settings>Messages>Send & Receive, tap the ID, sign out, then sign back in with a different ID (so each person's devices are using a separate ID for iMessage).  Note: you can still share the same ID for purchasing in Settings>iTunes & App Stores; or
    On all of the devices go to Settings>Messages>Send & Receive and uncheck the email address(es) shown under "You can be reached by iMessage at".  Also uncheck anyone else's phone number, if present.
    I you are sharing the same ID for FaceTime you may end up getting each other's FaceTime calls too.  To prevent this, go to Settings>FaceTime, tap the ID, sign out, then sign back in with a different ID (so each person's devices are using a different ID for FaceTime too).

  • My husband made the mistake of "upgrading" to IOS 7 last night.  Now he is receiving every text message that I send or receive.  How do I make this stop?

    My husband made the mistake of "upgrading" to IOS 7 last night.  Now he is receiving every text message that I send or receive.  How do I make this stop.  We have always shared the same Apple ID in the past and never had any problems.  I've seen posts where they say to create separate Apple ID's, but that means that whichever one of us does that, is gonna lose access to everything that is in our current ITunes account, correct? 

    My husband made the mistake of "upgrading" to IOS 7 last night.  Now he is receiving every text message that I send or receive.  How do I make this stop.  We have always shared the same Apple ID in the past and never had any problems.  I've seen posts where they say to create separate Apple ID's, but that means that whichever one of us does that, is gonna lose access to everything that is in our current ITunes account, correct? 

  • I am running OS X10.4.11 Recently I have been having trouble opening entourage, word, safari, excel, etc on a cold start  It has been taking 3 attempts  each time getting a message that the program quit unexpectedly.  Seems like a virus.  What can I do?

    1st attempt to open an application after the computer has been shut down a message says(as an example)" the application PowerPoint quit unexpectedly.  Mac OS X and other applications are not affected.  Click reopen to see more details or send a report to Apple."  Next attempt it says "The application PowerPoint quit unexpectedly after it was reopened.  Mac Os X and other applications are not affected.  Click Try Again to temporarily restore the application's default settings and open it again.  Click Report to see more details or send a report to Apple."  When I click "Try Again"  the app opens normally and usually runs ok  sometimes it will quit unexpectedly but when reopening at that point it opens ok.  Never had this issue until about 2 weeks ago.  ***  When I close the program myself I get a message that says "PowerPoint-New Settings
    New settings have been created for this application.  Do you want to use these settings from now on?  Then there  are  2 buttons below the dialogue box that say "Use new settings and Use original settings"  This happens every time I try to open Power Point, Excel, Safari, Entourage the first time each new day.  If I have been running any of those programs and have not shut down the laptop then the program will reopen normally but may shut down unexpectedly on its own  and sometimes not. What changed and how do I fix this problem?  Running OS X10.4.11 and software updates are current.  Ran diagnostics and checked out ok.

    Very Important, how much Free Space is on your Hard Drive first of all? Click on the Macintosh HD on the Desktop, then do a Get Info on it.
    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.
    Do they launch OK while in Safe Mode?

  • Why do some SMS messages that I send to friends appear on my husbands iPhone?  I previously sent them a message from my iPad.....

    Why do SMS messgaes appear on my husbands iPhone, that I send to friends that I have previously sent messages from my iPad?
    We have no pc, just iPad 2 and iPhones and the magical cloud!,
    Cheers

    Are you sharing an Apple ID?
    Go to Settings>Messages>Send and receive and unselect his phone number from your iPhone and yours from his.
    Also make sure that each of the phones are sending from their own numbers

  • Just installed OS X Yosemite and I cannot open PS3 without Java SE 6 runtime.  It doesn't seem to be available.  I have downloaded Java 8, but I still get the message that I must download Java SE 6.

    Any ideas or suggestions?

    You need to use the Java version from the apple website
    http://support.apple.com/kb/DL1572
    Other versions of java from the java website won't work for adobe products that say they need Java SE 6

  • Java card Applet RSA encryption Problems with Android

    hi all,I am new to java card development. I have used nxp jcop 31-36 java card and nexus s for testing the application.so i have faced lot of problems.first of all i want to encrypt data coming from the android app using RSA1024 and send back to the android application.there are the problems I faced
    1.RSA1024 and RSA2048 algorithms can't work with the nexus s Application.it means i can't receive any encrypt data from card.but when i test the application with eclipse jcop shell tool it is work properly.
    2.when i run the application in nexus s the application is crashed.it gives some wired sound when tap the java card to android phone.it may be java card application crashed or give some wired sound from android OS level.
    3.Then I Test the Application with Samsung S2. Sometimes it works but sometimes it crashed.in the S2 the encryption works fine(but we have to keep wile card 2 or 3 minutes).
    these are the steps i followed in established the connection i android phone.So fist i created the ISO dep connection and first select the Application(00A40400AID).Then using transive method i send data to java card.In the Java card in the installation i have created the RSA key pairs and get the RSA public key and private key.in some method i got the APDU buffer and read data and encrypt this data.Then those are send back to the card. First i want to know is there any problem in Android Os or JCOP 31/36 card.And other thing each time i requested to java crd is that need to reset the java card and how to reset the Java card.(some brief idea)

    Hi,
    1) Import android.smartcard libraries,
    2) Try to make a connection :
    ISmartcardConnectionListener connectionListener = new ISmartcardConnectionListener()3) create an instance of smartcardclient:
    smartcard = new SmartcardClient(this, connectionListener);4) get the list of readers :
    String[] readers = smartcard.getReaders();you can check if a specific reader is connected or nor with
    smartcard.isCardPresent(readers [0]);5) create a card channel and select your applet:
    cardChannel = smartcard.openLogicalChannel(cardReader, APPLET_AID);
    ICardChannel cardChannel = null;
    cardChannel = smartcard.openLogicalChannel(cardReader, APPLET_AID);6) you can send and receive APDUs with this line of code:
    byte[] response Apdu = cardChannel.transmit(commandApdu);Regards,
    Hana

  • I have a few individual files I want to encrypt. Is that capability builtin

    Can Tiger let me password-protect a file? I have a few with passwords and junk on it that I'd rather not have just sitting on my network hidden.

    Click here and follow the instructions.
    (30295)

  • HT4865 Can my text messages that I send and are sent to me be retrieved

    Are texts messages saved anywhere in Iphone 5c or on the icloud?

    The only way you can do that is if you use a texting service (Gmail SMS maybe) that would allow you to do so, but as far as veiwing your VZW text messages online, no you can't.

  • I am receiving the same text messages that i send out to another person?

    Recently activated a new iphone 5c and i send a text out but two people are receiving the text.  I know it is due to our Apple Account but i can't figure out how to change this.

    go to settings- messages - send and receive- select the numbers and emails you want to use - deselect the ones you don't need
    Peace, Clyde

  • I just updated my husbands phone to ios8 and also mine. When I did his, now everytime I text him, i get the same text message from myself. I also get his text messages that he sends.

    I updated my phone to ios8 by connecting to my computer. I then updated my husbands phone to ios8. Since then, I get every message he sends (as an imessage) and I also get my own messages back when I send him a message (text). I connected them to the same computer. I have now changed it so we have different apple id's, but at the time, it was the same. HELP!

    Stop using the same AppleID.  That's why you're getting each other's messages.

Maybe you are looking for

  • 11gR2 Grid Infrastucture Installation Problem on HP-UX 11.31

    While installing Oracle 11gR2 Grid Infrastructure on HP-UX 11.31 it is giving error message INS-06006: Passwordless SSH connectivity not set up between the following node(s), but manually it is working fine from both nodes. What to do now, any sugges

  • WRT54G and WRT54GS Linksys EasyLink Advisor (LELA) users

    If you are experiencing any issues with Linksys EasyLink Advisor (LELA) and the latest firmware on the Linksys.com, you may have to roll back your firmware version.  Linksys EasyLink Advisor (LELA) may not function properly with the firmware revision

  • Doubts in plant maintenance

    what are the business process in plant maintenance. what are oraganisational level inside sap-pm.

  • OAM - Force password reset - eDirectory

    I have a form based authentication scheme that uses eDirectory. Authentication is working. What I want to do is force all users to change their password upon next login. I set up a password policy and defined my Password Change Redirect URL and Passw

  • How to put a button beside a selectOneChoice, mantaining the alignement

    Hi all, I am using Jdev 11.1.1.0.2. I have a panelFormLayout containing some selectOneChoice components. I'd like to put a a commandButton beside every selectOneChoice. I have tried to surrond the selectOneChoiceComponent and their associated button