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

AW: [iaik-jce] PBE Encryption and SealedObjects



Sorry,

as unfortunately not mentioned by the Javadoc, method getObject(Key) is not
implemented by IAIK SealedObject. Please init with the Cipher object
(getObject(Cipher c)).

A PBE example:


import javax.crypto.SecretKey;
import javax.crypto.Cipher;
import javax.crypto.spec.PBEParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.SecretKeyFactory;

public class PBE1 {

  // Salt simple is a Byte Array
  static final byte[] salt = {
    (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
    (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
  };
  // Iteration count
  static final int iterationCount = 20;

  /**
   * main methode.
   */
  public static void main(String[] argv) {


    iaik.security.provider.IAIK.addAsProvider();

    try {
      // salt und iterationCount as PBE Parameter
      PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt,
iterationCount);
      // password:
      char[] password = {'S', 'e', 'c', 'r', 'e', 't', '!'};

      // generate key spec
      PBEKeySpec pbeKeySpec = new PBEKeySpec(password);

      // SecretKeyFactory for conversion
      SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBE");
      SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

      // cipher
      Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
      pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

      byte[] cleartext = "Nur ein Beispiel!".getBytes();
      // encrypt
      byte[] encrypted = pbeCipher.doFinal(cleartext);

      // decryption
      pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
      pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
      byte[] decrypted = pbeCipher.doFinal(encrypted);

      System.out.println("Result: "+new String(decrypted));

    } catch (Exception ex) {
      System.out.println(ex);
      ex.printStackTrace();
    }
  }
}




Regards,
Dieter Bratko

-----Ursprüngliche Nachricht-----
Von: iaik-jce-owner@iaik.tu-graz.ac.at
[mailto:iaik-jce-owner@iaik.tu-graz.ac.at]Im Auftrag von Kevin Crosbie
Gesendet: Dienstag, 15. August 2000 23:55
An: iaik-jce@iaik.at
Betreff: [iaik-jce] PBE Encryption and SealedObjects


Hi,

I've been having lots of trouble with symmetric encryption.   Much of the
time that I try to use PBE encryption, I encrypt, then decrypt, and get out
garbled text.   Does anyone have a very good example of using PBE
encryption.

Anyway, that is not the main question.  My main question is with
SealedObjects.   I used the sealedObject in the same way that the JCE/JCA
states in: http://crypto.stanford.edu/~dabo/cs255/JCE-1.2.htm#SealedObject

Only problem is that when I try to get out my origional plaintext, and place
in the origional key or the cipher,  I get a null returned on:
String temp = (String)so.getObject(sk);

Can anyone see why this would be happening... I have done exactly as the
document says.

Thanks,

Kevin
--
Mailinglist-archive at
http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content:
UNSUBSCRIBE iaik-jce




smime.p7s