Example usage for javax.crypto SealedObject getAlgorithm

List of usage examples for javax.crypto SealedObject getAlgorithm

Introduction

In this page you can find the example usage for javax.crypto SealedObject getAlgorithm.

Prototype

public final String getAlgorithm() 

Source Link

Document

Returns the algorithm that was used to seal this object.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    SecretKey key = KeyGenerator.getInstance("DES").generateKey();

    Cipher ecipher = Cipher.getInstance("DES");
    ecipher.init(Cipher.ENCRYPT_MODE, key);

    SealedObject so = new SealedObject(new MySecretClass(), ecipher);

    String algoName = so.getAlgorithm(); // DES

    Cipher dcipher = Cipher.getInstance("DES");
    dcipher.init(Cipher.DECRYPT_MODE, key);
    MySecretClass o = (MySecretClass) so.getObject(dcipher);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SecretKey key = (SecretKey) readFromFile("secretkey.dat");
    SealedObject sealedObject = (SealedObject) readFromFile("sealed.dat");
    String algorithmName = sealedObject.getAlgorithm();
    Cipher cipher = Cipher.getInstance(algorithmName);
    cipher.init(Cipher.DECRYPT_MODE, key);
    String text = (String) sealedObject.getObject(cipher);
    System.out.println("Text = " + text);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    SecretKey secretKey;/*from w w  w  .  j  a  v  a 2s  .c om*/
    Cipher encrypter, decrypter;

    secretKey = KeyGenerator.getInstance("DES").generateKey();

    encrypter = Cipher.getInstance("DES");
    encrypter.init(Cipher.ENCRYPT_MODE, secretKey);

    decrypter = Cipher.getInstance("DES");
    decrypter.init(Cipher.DECRYPT_MODE, secretKey);

    MyClass cust, unsealed;
    SealedObject sealed;

    cust = new MyClass();
    cust.name = "Paul";
    cust.password = "password";

    // Seal it, storing it in a SealedObject
    sealed = (new SealedObject(cust, encrypter));

    // Try unsealing it
    String algorithmName = sealed.getAlgorithm();
    System.out.println(algorithmName);
    unsealed = (MyClass) sealed.getObject(decrypter);

    System.out.println("NAME: " + unsealed.name);
    System.out.println("PASSWORD: " + unsealed.password);

}