[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] SealedObject

In this test the object seals and writes to the file fine.  But when I unseal it it always comes up null, yet no error is thrown.  If someone could tell me what I'm doing wrong I would greatly appreciate it.
  private static void testSealedObject()
    String fileName = "E:\\test.ser";
    Integer newInt = new Integer(1);
      FileOutputStream fout = new FileOutputStream(fileName);
      ObjectOutputStream oout = new ObjectOutputStream(fout);
      // create a key
      byte[] desKeyData = {(byte) 0x90, (byte) 0x67, (byte) 0x3E, (byte) 0xE6,
          (byte) 0x42, (byte) 0x15, (byte) 0x7A, (byte) 0xA3};
      DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
      SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
      SecretKey desKey = skf.generateSecret(desKeySpec);
      // create a cipher
      Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
      desCipher.init(Cipher.ENCRYPT_MODE, desKey);
      // seal the object and write it to a file
      SealedObject so = new SealedObject(newInt, desCipher);
      // retrieve the sealed object from a file
      FileInputStream fin = new FileInputStream(fileName);
      ObjectInputStream oin = new ObjectInputStream(fin);
      SealedObject soFromFile = (SealedObject) oin.readObject();
      Integer anotherInt = (Integer) soFromFile.getObject(desKey);
      // console output here is "null"!  why?
    catch (Exception e)