Package javax.crypto

Examples of javax.crypto.SealedObject


        try {
            byte[] data = Base64.decode(source);
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.DECRYPT_MODE, SECRET_KEY);
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
            SealedObject so = (SealedObject) in.readObject();
            return so.getObject(c);
        } catch (Exception e) {
            log.error("Unable to decrypt", e);
            return null;
        }
    }
View Full Code Here


     */
    public static String encrypt(Serializable source) {
        try {
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.ENCRYPT_MODE, SECRET_KEY);
            SealedObject so = new SealedObject(source, c);
            ByteArrayOutputStream store = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(store);
            out.writeObject(so);
            out.close();
            byte[] data = store.toByteArray();
View Full Code Here

        try {
            byte[] data = Base64.decode(source);
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.DECRYPT_MODE, SECRET_KEY);
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
            SealedObject so = (SealedObject) in.readObject();
            return so.getObject(c);
        } catch (Exception e) {
            log.error("Unable to decrypt", e);
            return null;
        }
    }
View Full Code Here

     */
    public static String encrypt(Serializable source) {
        try {
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.ENCRYPT_MODE, SECRET_KEY);
            SealedObject so = new SealedObject(source, c);
            ByteArrayOutputStream store = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(store);
            out.writeObject(so);
            out.close();
            byte[] data = store.toByteArray();
View Full Code Here

        try {
            byte[] data = Base64.decode(source);
            Cipher c = Cipher.getInstance("AES");
            c.init(Cipher.DECRYPT_MODE, SECRET_KEY);
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
            SealedObject so = (SealedObject) in.readObject();
            return so.getObject(c);
        } catch (Exception e) {
            log.error("Unable to decrypt", e);
            return null;
        }
    }
View Full Code Here

    public String encrypt(Serializable source) {
        SecretKeySpec spec = getSecretKeySpec();
        try {
            Cipher c = Cipher.getInstance(spec.getAlgorithm());
            c.init(Cipher.ENCRYPT_MODE, spec);
            SealedObject so = new SealedObject(source, c);
            ByteArrayOutputStream store = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(store);
            out.writeObject(so);
            out.close();
            byte[] data = store.toByteArray();
View Full Code Here

        try {
            byte[] data = Base64.decode(source);
            Cipher c = Cipher.getInstance(spec.getAlgorithm());
            c.init(Cipher.DECRYPT_MODE, spec);
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
            SealedObject so = (SealedObject) in.readObject();
            return (Serializable) so.getObject(c);
        } catch (Exception e) {
            log.error("Unable to decrypt", e);
            return null;
        }
    }
View Full Code Here

  public void setMessage(Serializable message) throws RemoteException {
    if (this.cryptoSwitch) {
      KeyPair keyPair = this.sender.getKeyPair();
      try {
        Cipher cipher = KeyController.publicEncryptCipher(keyPair);
        this.message = new SealedObject(message, cipher);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      this.message = message;
View Full Code Here

    if (message.isCrypted()) {
      ChatMemberModelInterface chatMemberModelInterface = message.getSender();
      KeyPair keyPair = chatMemberModelInterface.getKeyPair();
      try {
        Cipher cipher = KeyController.privateDecryptCipher(keyPair);
        SealedObject object = (SealedObject)message.getMessage();
        System.out.println(object.getObject(cipher));
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("[" + message.getSender().getName() + "]: " + message.getMessage());
View Full Code Here

        return o;
    }

    private Object sealUnseal(Serializable o) throws Exception {
        PrivateCrypto pc = new PrivateCrypto("TripleDES", 168);
        SealedObject so = pc.seal(o);
        o = pc.unseal(so);
        return o;
    }
View Full Code Here

TOP

Related Classes of javax.crypto.SealedObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.