An Interesting RSA Decryption Problem

Hi,
Here is my function which does decryption:
private void key_load (APDU apdu)
        byte [] apduBuffer = apdu.getBuffer();
         apdu.setIncomingAndReceive();
        cipherRSA2.init(PrivateKey, Cipher.MODE_DECRYPT);
     cipherRSA2.doFinal(apduBuffer, (short)ISO7816.OFFSET_CDATA, (short)64, apduBuffer, (short)ISO7816.OFFSET_CDATA);
        apdu.setOutgoingAndSend((short)5, (short)70);          
}I generate RSA Key and get Public Key from my applet. I encrypt
"13131313131313130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
data with another tool with public key of my applet. My applet can decrypt this data perfectly.
And I encrypt
"FAFAFAFAFAFAFAFA0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
" data and send it to my applet to decrypt it however my applet cant decrypt it, it returns different data..
What is wrong with my code? Help me plese :/
Thanks in Advance,
Best Regards

I am not 100% sure about this but I think the problem is because the text you are encrypting in the second example when converted to a number is a negative number. Since RSA works by converting the key and text into large integers and performing a mathematical operation on them.
You might be better off using something like PKCS#1 padding (EM = 0x00 || 0x02 || PS || 0x00 || M where PS are non-zero bytes and M is the message). If you use the appropriate cipher, the padding will be handled for you.
Cheers,
Shane

Similar Messages

  • RSA Decryption Error - Illegal Use

    Hi there,
    i have a crypthographic problem using a JavaCard application and a Java host application.
    On the card i create a cipher object and a private/public key:
    Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1_OAEP, false);
    KeyPair kP = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1984);
    kP.genKeyPair();
    RSAPublicKey app_public_key = (RSAPublicKey) kP.getPublic();
    RSAPrivateKey app_private_key = (RSAPrivateKey) kP.getPrivate();There are two functions on the card to send the modulus and the exponent from the public key to the host application using two APDUs.
    private void sendModulus(APDU apdu)
         byte[] buffer = apdu.getBuffer();
         short modLength = app_public_key.getModulus(buffer, (short)ISO7816.OFFSET_CDATA);
         apdu.setOutgoing();
         apdu.setOutgoingLength(modLength);
         apdu.sendBytesLong(buffer, (short)ISO7816.OFFSET_CDATA, modLength);
    private void sendExponent(APDU apdu)
         byte[] buffer = apdu.getBuffer();
         short expLength = app_public_key.getExponent(buffer, (short)ISO7816.OFFSET_CDATA);
         apdu.setOutgoing();
         apdu.setOutgoingLength(expLength);
         apdu.sendBytesLong(buffer, (short)ISO7816.OFFSET_CDATA, expLength);
    }On the host i request the modulus and the exponent and build the public key:
    public void getAppMod() throws TerminalException
                      //get modulus
         ResponseApdu response = send(new CommandApdu("0x00 0xAA 0x01 0x00"));
         System.out.println(response.getStatusHexString());
         byte[] modulus = response.getData().toByteArray();
                      //get exponent
         ResponseApdu response = send(new CommandApdu("0x00 0xAA 0x02 0x00"));
         System.out.println(response.getStatusHexString());
         byte[] exponent = response.getData().toByteArray();
                      RSAPublicKeySpec kSpec = new RSAPublicKeySpec(new BigInteger(1, mod), new BigInteger(1, exp));
         KeyFactory kFac = KeyFactory.getInstance("RSA");
         RSAPublicKey app_rsa_publicKey = (RSAPublicKey)kFac.generatePublic(kSpec);
    }Now i create a cipher object on the host application, encrypt a message with this public key and send it to the card:
    Security.addProvider(new BouncyCastleProvider());
    Cipher cipher = Cipher.getInstance("RSA", "BC");
    cipher.init(Cipher.ENCRYPT_MODE, app_rsa_publicKey);
    byte[] cipherData = cipher.doFinal(bData); //bData is the message and cipherData the encrypted 248byte message.On the card now im trying to decrypt it with the private key.
    byte[] buffer = apdu.getBuffer();
    short bytesRead = apdu.setIncomingAndReceive();
    cipher.init(app_private_key, Cipher.MODE_DECRYPT);
    short messageLength = cipher.doFinal(buffer, (short)ISO7816.OFFSET_CDATA, bytesRead, buffer, (short)ISO7816.OFFSET_CDATA);
    }But the "doFinal" method throws an "ILLEGAL_USE" Exception...
    I dont know what to do now....
    Is it possible that the "BouncyCastle" Cipher object on the host side does not fit the cipher object on the card side ? because the key was transfered correctlly :(
    is there any provider i can use whre i dont need a free library like bouncycastle ?
    Thanks for helping...
    Edited by: 963778 on 08.10.2012 01:56

    Hi again,
    i think i solved my problem.
    So far it seems it wasnt the same RSA padding on card an host.
    After create the cipher on the card this way:
    cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);And on the host this way:
    cipher = Cipher.getInstance("RSA/NONE/PKCS1Padding", "BC");it works fine from host to card.
    The other way from card to host i get an "unknown block type" error.

  • RSA decryption Error: Data must start with zero

    Because of some reasons, I tried to use RSA as a block cipher to encrypt/decrypt a large file. When I debug my program, there some errors are shown as below:
    javax.crypto.BadPaddingException: Data must start with zero
         at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
         at sun.security.rsa.RSAPadding.unpad(Unknown Source)
         at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
         at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:394)
         at javax.crypto.Cipher.doFinal(Cipher.java:2299)
         at RSA.RRSSA.main(RRSSA.java:114)
    From breakpoint, I think the problem is the decrypt operation, and Cipher.doFinal() can not be operated correctly.
    I searched this problem from google, many people met the same problem with me, but most of them didn't got an answer.
    The source code is :
    Key generation:
    package RSA;
    import java.io.FileOutputStream;
    import java.io.ObjectOutputStream;
    import java.security.KeyPair;
    import java.security.KeyPairGenerator;
    import java.security.PrivateKey;
    import java.security.PublicKey;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class GenKey {
          * @param args
                     * @author tang
         public static void main(String[] args) {
              // TODO Auto-generated method stub
                 try {
                      KeyPairGenerator KPG = KeyPairGenerator.getInstance("RSA");
                      KPG.initialize(1024);
                      KeyPair KP=KPG.genKeyPair();
                      PublicKey pbKey=KP.getPublic();
                      PrivateKey prKey=KP.getPrivate();
                      //byte[] publickey = decryptBASE64(pbKey);
                      //save public key
                      FileOutputStream out=new FileOutputStream("RSAPublic.dat");
                      ObjectOutputStream fileOut=new ObjectOutputStream(out);
                      fileOut.writeObject(pbKey);
                      //save private key
                          FileOutputStream outPrivate=new FileOutputStream("RSAPrivate.dat");
                      ObjectOutputStream privateOut=new ObjectOutputStream(outPrivate);
                                 privateOut.writeObject(prKey)
         }Encrypte / Decrypt
    package RSA;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.ObjectInputStream;
    import java.security.Key;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.crypto.Cipher;
    //import sun.misc.BASE64Decoder;
    //import sun.misc.BASE64Encoder;
    public class RRSSA {
          * @param args
         public static void main(String[] argv) {
              // TODO Auto-generated method stub
                //File used to encrypt/decrypt
                 String dataFileName = argv[0];
                 //encrypt/decrypt: operation mode
                 String opMode = argv[1];
                 String keyFileName = null;
                 //Key file
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 keyFileName = "RSAPublic.dat";
                 } else {
                 keyFileName = "RSAPrivate.dat";
                 try {
                 FileInputStream keyFIS = new FileInputStream(keyFileName);
                 ObjectInputStream OIS = new ObjectInputStream(keyFIS);
                 Key key = (Key) OIS.readObject();
                 Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding");//
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 cp.init(Cipher.ENCRYPT_MODE, key);
                 } else if (opMode.equalsIgnoreCase("decrypt")) {
                 cp.init(Cipher.DECRYPT_MODE, key);
                 } else {
                 return;
                 FileInputStream dataFIS = new FileInputStream(dataFileName);
                 int size = dataFIS.available();
                 byte[] encryptByte = new byte[size];
                 dataFIS.read(encryptByte);
                 if (opMode.equalsIgnoreCase("encrypt")) {
                 FileOutputStream FOS = new FileOutputStream("cipher.txt");
                 //RSA Block size
                 //int blockSize = cp.getBlockSize();
                 int blockSize = 64 ;
                 int outputBlockSize = cp.getOutputSize(encryptByte.length);
                 /*if (blockSize == 0)
                      System.out.println("BLOCK SIZE ERROR!");       
                 }else
                 int leavedSize = encryptByte.length % blockSize;
                 int blocksNum = leavedSize == 0 ? encryptByte.length / blockSize
                 : encryptByte.length / blockSize + 1;
                 byte[] cipherData = new byte[outputBlockSize*blocksNum];
                 //encrypt each block
                 for (int i = 0; i < blocksNum; i++) {
                 if ((encryptByte.length - i * blockSize) > blockSize) {
                 cp.doFinal(encryptByte, i * blockSize, blockSize, cipherData, i * outputBlockSize);
                 } else {
                 cp.doFinal(encryptByte, i * blockSize, encryptByte.length - i * blockSize, cipherData, i * outputBlockSize);
                 //byte[] cipherData = cp.doFinal(encryptByte);
                 //BASE64Encoder encoder = new BASE64Encoder();
                 //String encryptedData = encoder.encode(cipherData);
                 //cipherData = encryptedData.getBytes();
                 FOS.write(cipherData);
                 FOS.close();
                 } else {
                FileOutputStream FOS = new FileOutputStream("plaintext.txt");
                 //int blockSize = cp.getBlockSize();
                 int blockSize = 64;
                 //int j = 0;
                 //BASE64Decoder decoder = new BASE64Decoder();
                 //String encryptedData = convert(encryptByte);
                 //encryptByte = decoder.decodeBuffer(encryptedData);
                 int outputBlockSize = cp.getOutputSize(encryptByte.length);
                 int leavedSize = encryptByte.length % blockSize;
                 int blocksNum = leavedSize == 0 ? encryptByte.length / blockSize
                           : encryptByte.length / blockSize + 1;
                 byte[] plaintextData = new byte[outputBlockSize*blocksNum];
                 for (int j = 0; j < blocksNum; j++) {
                 if ((encryptByte.length - j * blockSize) > blockSize) {
                      cp.doFinal(encryptByte, j * blockSize, blockSize, plaintextData, j * outputBlockSize);
                      } else {
                      cp.doFinal(encryptByte, j * blockSize, encryptByte.length - j * blockSize, plaintextData, j * outputBlockSize);
                 FOS.write(plaintextData);
                 //FOS.write(cp.doFinal(encryptByte));
                 FOS.close();
    }Edited by: sabre150 on Aug 3, 2012 6:43 AM
    Moderator action : added [ code] tags so as to make the code readable. Please do this yourself in the future.
    Edited by: 949003 on 2012-8-3 上午5:31

    1) Why are you not closing the streams when writing the keys to the file?
    2) Each block of RSA encrypted data has size equal to the key modulus (in bytes). This means that for a key size of 1024 bits you need to read 128 bytes and not 64 bytes at a time when decrypting ( this is probably the cause of your 'Data must start with zero exception'). Since the input block size depends on the key modulus you cannot hard code this. Note - PKCS1 padding has at least 11 bytes of padding so on encrypting one can process a maximum of the key modulus in bytes less 11. Currently you have hard coded the encryption block at 64 bytes which is OK for your 1024 bits keys but will fail for keys of modulus less than about 936 bits.
    3) int size = dataFIS.available(); is not a reliable way to get the size of an input stream. If you check the Javadoc for InputStream.available() you will see that it returns the number of bytes that can be read without blocking and not the stream size.
    4) InputStream.read(byte[]) does not guarantee to read all the bytes and returns the number of bytes actually read. This means that your code to read the content of the file into an array may fail. Again check the Javadoc. To be safe you should used DataInputStream.readFully() to read a block of bytes.
    5) Reading the whole of the cleartext or ciphertext file into memory does not scale and with very large files you will run out of memory. There is no need to do this since you can use a "read a block, write the transformed block" approach.
    RSA is a very very very slow algorithm and it is not normal to encrypt the whole of a file using it. The standard approach is to perform the encryption of the file content using a symmetric algorithm such as AES using a random session key and use RSA to encrypt the session key. One then writes to the ciphertext file the RSA encrypted session key followed by the symmetric encrypted data. To make it more secure one should actually follow the extended procedure outlined in section 13.6 of Practical Cryptography by Ferguson and Schneier.

  • 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);

  • Rsa Decrypt Not Working.. Please Help

    Hi everyone,
         I am new to java card development. I have been trying to use RSA encryption in my Applet. I finally got the encryption working but the decryption is showing Illegal Use Error. Any kind of help is appreciated.
    public class RSAsample extends Applet{
    byte[] rsaPublic = new byte[4];
    byte[] rsaPrivate = new byte[4];
    byte[] rsaPublicMod = new byte[4];
    RSAPrivateKey pri ;
    RSAPublicKey pub ;
    private final static byte INS_ENCRYPT = (byte) 0x20;
    private final static byte INS_DECRYPT = (byte) 0x30;
    KeyPair pair ;
    private RSAsample() {
      super();
      register();
    public static void install(byte bArray[], short bOffset, byte bLength)
      throws ISOException {
      new RSAsample();
    public boolean select() {
      pair = new KeyPair(KeyPair.ALG_RSA, (short) 512);
      pair.genKeyPair();
    pri = (RSAPrivateKey) pair.getPrivate();
    pub = (RSAPublicKey) pair.getPublic();
      return super.select();
    public void deselect() {
      super.deselect();
       public void process(APDU apdu) throws ISOException {
        byte[] buffer = apdu.getBuffer();
        switch(buffer[ISO7816.OFFSET_INS])
        case INS_ENCRYPT:
        encrypt(apdu);
        break;
        case INS_DECRYPT:
        decrypt(apdu);
        break;
    private void decrypt(APDU apdu) {
      byte[] buffer = apdu.getBuffer();
      byte byteRead = (byte)(apdu.setIncomingAndReceive());
      short size = 0;
      try{
      Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
      cipher.init(pri, Cipher.MODE_DECRYPT);
      size =  cipher.doFinal(buffer, ISO7816.OFFSET_CDATA, (short)byteRead, buffer,
      (short) 0);
      catch(CryptoException e)
      switch(e.getReason())
      case CryptoException.ILLEGAL_USE:
      ISOException.throwIt(ISO7816.SW_DATA_INVALID);
      break;
      case CryptoException.ILLEGAL_VALUE:
      ISOException.throwIt(ISO7816.SW_FILE_INVALID);
      break;
      case CryptoException.INVALID_INIT:
      ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
      break;
      case CryptoException.NO_SUCH_ALGORITHM:
      ISOException.throwIt(ISO7816.SW_FILE_INVALID);
      break;
      case CryptoException.UNINITIALIZED_KEY:
      ISOException.throwIt(ISO7816.SW_FILE_FULL);
      break;
      default:
      ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
      break;
      apdu.setOutgoing();
      apdu.setOutgoingLength(size);
      apdu.sendBytes((short)0, size);
    private void encrypt(APDU apdu) {
      byte[] buffer = apdu.getBuffer();
      byte byteRead = (byte)(apdu.setIncomingAndReceive());
      short size = 0;
      try{
      Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
      cipher.init(pub, Cipher.MODE_ENCRYPT);
      size =  cipher.doFinal(buffer, ISO7816.OFFSET_CDATA, (short)byteRead, buffer,
      (short) 0);
      catch(CryptoException e)
      switch(e.getReason())
      case CryptoException.ILLEGAL_USE:
      ISOException.throwIt(ISO7816.SW_DATA_INVALID);
      break;
      case CryptoException.ILLEGAL_VALUE:
      ISOException.throwIt(ISO7816.SW_FILE_INVALID);
      break;
      case CryptoException.INVALID_INIT:
      ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
      break;
      case CryptoException.NO_SUCH_ALGORITHM:
      ISOException.throwIt(ISO7816.SW_FILE_INVALID);
      break;
      case CryptoException.UNINITIALIZED_KEY:
      ISOException.throwIt(ISO7816.SW_FILE_FULL);
      break;
      default:
      ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
      break;
      apdu.setOutgoing();
      apdu.setOutgoingLength(size);
      apdu.sendBytes((short)0, size);
    Also if this is wrong can you share a sample code using RSA Encryption and Decryption.
    Thanks

    Hi,
    You code looks perfectly fine.
    Looking at the error code i think you are sending some invalid data for decryption operation.
    You should send data which was encrypted using the same PublicKey other wise it will fail while matching the Padding or Data Blocks.
    For better understanding Encrypt some data and immediately use the output data for Decrypt operation and it should work fine.
    Let me know if you face any difficulties.
    BR,
    PPT

  • Simple RSA decryption error

    Hi All
    I am trying a very simple RSA implementations. I am not able to decrypt the data correctly. Please find my code below,
    import java.math.BigInteger;
    import java.util.Random;
    public class SimpleRSA {
         public static BigInteger p, q, N, v, k, d;
         public static void main(String[] args) {
              // p & q are prime numbers
              Random myRandom = new Random(0);
              p = BigInteger.probablePrime(32, myRandom);
              q = BigInteger.probablePrime(32, myRandom);
              System.out.println("Value of p:" + p);
              System.out.println("Value of q:" + q);
              // N = pq
              N = p.multiply(q);
              System.out.println("Value of N:" + N);
              // v = (p-1)*(q-1)
              v =
                   (p.subtract(BigInteger.valueOf(1))).multiply(
                        q.subtract(BigInteger.valueOf(1)));
              System.out.println("Value of v:" + v);
              // Compute k such that gcd(k, v) = 1
              k = new BigInteger("3");
              while(v.gcd(k).intValue() > 1) k = k.add(new BigInteger("2"));
              System.out.println("Value of k:" + k);
              // Compute d such that (d * k)%v = 1
              d = k.modInverse(v);
              System.out.println("Value of d:" + d);
              System.out.println("Public Key (k,N): (" + k + "," + N + ")");
              System.out.println("Private Key (d,N): (" + d + "," + N + ")");
              // Encryption
              String text = "Welcome to Java";
              System.out.println("Sample text:" + text);
              byte[] cipherData = text.getBytes();
              BigInteger a = new BigInteger(cipherData);
              System.out.println("BigInteger a:" + a);          
              BigInteger b = a.modPow(k, N);
              System.out.println("Encrypted data:" + b);
              // Decryption
              BigInteger c = b.modPow(d, N);
              byte[] decryptedData = c.toByteArray();          
              String plainText = new String(decryptedData);
              System.out.println("Decrypted data:" + plainText);     
    The answer I am getting is like this
    Value of p:3139482721
    Value of q:3180579707
    Value of N:9985375032889742747
    Value of v:9985375026569680320
    Value of k:7
    Value of d:4279446439958434423
    Public Key (k,N): (7,9985375032889742747)
    Private Key (d,N): (4279446439958434423,9985375032889742747)
    Sample text:Welcome to Java
    BigInteger a:1446156601937412646258
    Encrypted data:9678387382297663676
    Decrypted data:r��`�>B[/i]
    Please help me in this regard.
    Regards
    Kathirvel

    "m" (the integer rep of the message) must be strictly less than "N" (p*q). Look at the output - your p and q are too small for your data. Tryp = BigInteger.probablePrime(512, myRandom);
    q = BigInteger.probablePrime(512, myRandom);and try again.
    Then, go back and re-read the description of the RSA algorithm:
    http://en.wikipedia.org/wiki/RSA
    ("Applied Cryptography" would be bettr - but Wikipedia is at least a good start...)
    Grant

  • Decrypt problem

    Hello!
    I have problem decripting string if the string is long.
    I use
    <cfset session.algo = "DES">
    <cfset session.key = GenerateSecretKey(session.algo)>
    <cfset session.enco = "HEX">
    I have tried and other but nothing works for me.
    also i do the encrypt like this: #URLEncodedFormat(Encrypt(tmpnodeid,session.key,session.algo,session.enco))#
    and i pass this value as url parameter, which btw sometimes is cut.
    Then i decrypt it like this: #Decrypt(URLDecode(URL.name),session.key,session.algo,session.enco)#
    Can anyone please help me?
    Thank you in advance!
    Kind regards!

    Hi
    i have only change to pass the string using url in this case.
    the sttring look something like this:
    73467_DFGSDFGFSDGSDFG_SDFGSDFGSDFGSD_SDF_DFGSDFGS
    The url is the whole encrypted string, i have checked it now.
    it is like this:
    in some page have outputed many links with this the string encrypted in the url.
    when click some of these strings, it redirects to the same page but it checks if the url is defined and if is defined shows diffrent portion of the code.
    Only english letters are used in the strings.

  • 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

  • FileVault decryption problem fixed

    I had posted on April 30 that I could not decrypt my FileVault home folder. TechToolPro 4 and Disk Utility both reported problems, but offered no solutions. Today I got a DiskWarrior CD, and it immediately found the problems and fixed them. Easy as pie. Wanted to post this in case others have similar issues with FileVault.

    Well done, and thanks for the post back.

  • Really interesting (and annoying) problem with Adobe on my printer...

    Hi all,
    I hope you'll be able to help me with this one, it is making me crazy. First, my configuration :
    Mac OS X 10.4.11 (iMac G5)
    Adobe Reader Version 8.1.2
    Printer HP LaserJet P1005
    I can print normally the usual pdf (have done it before and it is working perfectly). But I have just subscribe to a service which sends me "secured" pdf (I had to install a FileOpenWeb key; I can read those pdfs only on this computer and cannot edit them but I can print them - it is well specified in the security properties of the document and I contacted the supplier of the pdfs to confirm that it should be working). So I can open and read the pdf, but when I try to print them, Adobe crashes. Every time, without even popping up the usual print window. I just click on the prnter button and Adobe closes itself. If you know how to solve that problem, that would really be appreciated (a lot).
    Thanks in advance,
    Henri
    PS : for the real stuff, here is the mac error message :
    Date/Time: 2008-02-27 23:17:25.840 +0100
    OS Version: 10.4.11 (Build 8S165)
    Report Version: 4
    Command: AdobeReader
    Path: /Applications/Adobe Reader 8/Adobe Reader.app/Contents/MacOS/AdobeReader
    Parent: WindowServer [55]
    Version: 8.1.2 (8.1.2)
    PID: 255
    Thread: 0
    Exception: EXC_BAD_ACCESS (0x0001)
    Codes: KERN_INVALID_ADDRESS (0x0001) at 0x80000000
    Thread 0 Crashed:
    0 <<00000000>> 0xfffeff20 objc_msgSend_rtp + 32
    1 com.apple.CoreFoundation 0x907c5890 __CFURLDeallocate + 44
    2 com.apple.CoreFoundation 0x907bdd74 _CFRelease + 240
    3 com.adobe.acrobat.sdk.Starter 0x042cdfe8 GetWP3Nib + 524
    4 com.adobe.acrobat.sdk.Starter 0x042ceb7c LoadPrtDialogWindowFromNibFile + 88
    5 com.adobe.acrobat.sdk.Starter 0x042cf10c DoPrinterDialog + 76
    6 com.adobe.acrobat.sdk.Starter 0x042d0200 DoPrint + 700
    7 com.adobe.acrobat.sdk.Starter 0x04298f2c CheckThenPrint + 840
    8 com.adobe.acrobat.sdk.Starter 0x04299968 Fowp3AVDocPrintPagesWithParams + 136
    9 com.adobe.Acrobat.framework 0x8415df64 CopiesPagesPDE_Open + 227016
    10 com.adobe.Acrobat.framework 0x842bee4c CopiesPagesPDE_Open + 1672624
    11 com.adobe.Acrobat.framework 0x843127a0 CopiesPagesPDE_Open + 2014980
    12 com.adobe.Acrobat.framework 0x84312d78 CopiesPagesPDE_Open + 2016476
    13 com.adobe.Acrobat.framework 0x843dfef0 CopiesPagesPDE_Open + 2856532
    14 com.adobe.Acrobat.framework 0x84290cb4 CopiesPagesPDE_Open + 1483800
    15 com.adobe.Acrobat.framework 0x84292b28 CopiesPagesPDE_Open + 1491596
    16 com.adobe.Acrobat.framework 0x84284144 CopiesPagesPDE_Open + 1431720
    17 com.apple.AppKit 0x937df970 -[NSWindow sendEvent:] + 4616
    18 com.apple.AppKit 0x937889b4 -[NSApplication sendEvent:] + 4172
    19 com.apple.AppKit 0x9377fdf0 -[NSApplication run] + 508
    20 com.adobe.Acrobat.framework 0x83f8f6e0 RunAcrobat + 3188
    21 com.adobe.Acrobat.framework 0x83f8eb74 RunAcrobat + 264
    22 com.adobe.Reader 0x00003b2c start + 5956
    23 com.adobe.Reader 0x0000257c start + 404
    24 com.adobe.Reader 0x00002424 start + 60
    Thread 1:
    0 libSystem.B.dylib 0x9000b348 mach_msg_trap + 8
    1 libSystem.B.dylib 0x9000b29c mach_msg + 60
    2 com.apple.CoreFoundation 0x907dd9b8 __CFRunLoopRun + 832
    3 com.apple.CoreFoundation 0x907dd2bc CFRunLoopRunSpecific + 268
    4 ...dobe.AcrobatPlugin.Comments 0x8c69141c AcroPluginMain + 1225396
    5 ...dobe.AcrobatPlugin.Comments 0x8c692134 AcroPluginMain + 1228748
    6 ...ple.CoreServices.CarbonCore 0x90bc3794 PrivateMPEntryPoint + 76
    7 libSystem.B.dylib 0x9002bd08 _pthread_body + 96
    Thread 2:
    0 libSystem.B.dylib 0x9002c3c8 semaphore_wait_signal_trap + 8
    1 libSystem.B.dylib 0x90030eac pthread_cond_wait + 480
    2 com.apple.Foundation 0x92bed22c -[NSConditionLock

    Have you tried to repair disk permissions?
    (applications> utilities> disk utility.)
    then re-install the key.
    If that doesn't work, try as a new user.

  • Interest & Dunning related problem

    Hi All,
      I have configured for the interest calculation but the system is picking up the documents from the Document date and not from the net due date.
    In FINT is there any way out that the documents should be picked up from Net due date & not from Document date or posting date. I mean only the documents which are due should be picked up in interest run.
    I know it works with F.2C were only the due items get picked but can it happen in FINT.
    The same with Dunning all the docs are getting picked here only the due items should be picked.
    I know I can restrict the documents with Interest & Dunning Block
    But is there any config which I have missed for carrying out interest & dunning run for the documents which are only due.

    If you post one document , for this due date is calculated based on the payment terms.
    payment terms is calculating teh due date.
    ex:payment terms  is 15 days system will calculate teh due date  for 15 days,
    this 15 days calculation is based on baseline date.
    if you mention base line date is posting date, system will calculate the payment terms from teh posting date.
    chandra

  • Interesting though esoteric problem of the form 'select a * b from dual'

    Hi,
    Warning: The question is of very little practical significance.
    (There, I warned you!!)
    Database version: 10.2.0.4.0
    If I try to execute the following
    select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 999999999999999999999999999999999999999999
    from dualI get a 'ORA-01426: numeric overflow' error, which is fine.
    But if I try to execute the following(note the decimal point)
    select 3.14285712285715111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 * 7
      from dualI get a 'ORA-00923: FROM keyword not found where expected' error.
    Interestingly, if I remove any one digit from the first number(hence reducing its length by 1), the query works fine. Removing the spaces on either side of '*' still results in a 'ORA-00923: FROM keyword not found where expected' error though.
    Can anyone explain why?
    Regards,
    Sujoy

    Hi, Sujoy,
    There seems to be a limit of 255 characters (including decimal point) in a number literal. It doesn't seem to matter how m,any digits are before the decimal point and how many are after it. If you don't raise siome other error (such as "'ORA-01426: numeric overflow' error") first, then using a liteal with more than 255 characters will raise "'ORA-00923: FROM keyword not found where expected".
    Multiplying by 7 in your example doesn't matter; the compiler never gets that far, because the error occurs in the compilation.
    A sign doesn't matter, either, because signs are not part of the literal; they are operators applied to the value after the literal is evaluated. This is also evident because you can put withespace between the sign and the literal.

  • Interesting Regular Expression Problem

    Hi - I am fairly new to Java, but have some reg exp experience.
    Basically, I would like a regular expression to strip elements out of a text format. The elements are delimited by curly braces, very similar to Java. The problem is that the elements may contain other elements - the format is hierarchical. I need to extract the whole element, including its children.
    For example, I need to extract the B element from
    [A]
    a1     1
    a2     2
    b1     1
    b2     2
    [C]{
    c1     1
    c2     2}
    [C]{
    c1     3
    c2     4}}
    and the answer should be
    b1     1
    b2     2
    [C]{
    c1     1
    c2     2}
    [C]{
    c1     3
    c2     4}}
    The nature of the format is not fixed - I won't know how many child elements the B element contains.
    Can this be done using regular expressions, or do I have to write a custom string handling function?
    Thanks for any help.
    Mark

    :-) And I still don't understand it!It's quite easy though ;-) Suppose a word w is generated by some grammar.
    If this grammar is regular you can write word w as xyz where y is not the empty
    word and |x| < p. if w is generated by a regular grammar then xy^nz
    (n occurrences of y) can also be generated by the same grammar. That's
    the 'pumping' giggle part.
    Now suppose the language of nested parentheses is a regular language.
    All you have to do is find a word w = xyz where xy^nz is not part of the language.
    Let w= ((())) and x= ((, y= ( and z= ))), obviously xy^nz is not a properly nested
    parentheses word for n > 1. Note that every generated word in that language,
    long enough has to have that value p, where xy^nz |x| < p and xy^nz in the language.
    The pumping lemma giggle for context free languages is almost the same:
    you have to find two positions where the pumping fails/succeeds.
    kind regards,
    Jos (huhuh, he said 'pumping' ;-)

  • Here are interesting and baffling problems

    Hi All:
    Could any one, please, help us with the following problems we are facing while running an applet:
    We are using JDK 1.1.8.
    Our goal is to keep the display up and running even if the user navigates to different pages
    The applet loads up as a button and when clicked a pop-up frame window is displayed with the contents.
    We took care of the applet data to persist between page switches.
    * In IE when one switches to different page it kills the applet and we can't access the applet context to call "showDocument()". We tried all different ways to store it and access it later without any success. Could any one please throw some light on it.
    * In NS when one tries to minimize the frame window and tries to maximize it shows up as maximized with only the enclosing frame. But the embedded panels(contents) will retain the size they had before mimimizing. I printed the size of the frame window in "windowDeiconified()" and to my surprise it is still the size before miminizing. Could any one help us to solve this browser specific problem. From "windowDeiconified()" ,we tried to set a different size, called repaint()/update() but without any success.
    Please help us to solve these TWO problems
    We're running short of time.
    Thanks
    -Shiva

    You might want to try Java Web Start, which allows you to run a Java application from a browser. It sounds like you want an application instead of an applet.

  • Interesting Mail App Problem with 3G

    OK
    First off, I haven't had a chance to hit a computer to update to 2.2, Just moved to a new city and no high speed internet yet, maybe I can get a free update at a local Apple Store, See what happens here.
    But from the sounds of it and forum posts. its caused more problems then 2.1
    Anyways, Iphone 3G is using 2.1
    I added a Hushmail IMAP Account to it.
    I followed their Mac OS X Instructions and I can send and recieve email no problem.
    But,
    If I turn on push 15 mins, send a test mail to myself, my main mail ICON isn't showing a red number above it when I get email, It will make a quick vibrate and noise, but no number.
    Second, I have searched and searched.
    My Email isn't going into the MAIN Inbox in the Mail App
    Seems like it is being dumped into a Seperate INBOX folder below the main INBOX.
    I can see my spam mail folder etc as subfolders below the main INBOX and the INbox folder its dumping my mail into.
    I have tried adding /INBOX, INBOX, /Inbox, Inbox to my IMAP Path prefix and that doesn't seem to fix it and make my email going into the main INBOX.
    Hushmail just got a email from me asking them about a IMAP Path Prefix, see what they have to say.
    What does everyone else think here to solve this problem with the Updating and getting my email into the Main INBOX instead of a Sub-folder Inbox.
    Thanks for looking
    Total_War

    Not sure,but are thseyour settings?
    iCloud Mail setup, even in 10.4/10.5…
    Don't delete your old account yet. Just setup a new one in Mail>Preferences>Accounts, little plus icon. Choose IMAP as account type, not ,mac or MobileMe.
    IMAP (Incoming Mail Server) information:
    Server name: imap.mail.me.com
    SSL Required: Yes
    Port: 993
    Username: [email protected] (use your @me.com address from your iCloud account)
    Password: Your iCloud password
    SMTP (outgoing mail server) information:
    Server name: smtp.mail.me.com
    SSL Required: Yes
    Port: 587
    SMTP Authentication Required: Yes
    Username: [email protected] (use your @me.com address from your iCloud account)
    Password: Your iCloud password

Maybe you are looking for