Package javax.crypto

Examples of javax.crypto.SealedObject


/*    */
/*    */   public static SealedObject sealObject(Serializable ser)
/*    */     throws Exception
/*    */   {
/* 52 */     Cipher ci = EncryptionManager.getCipher(1, algo);
/* 53 */     return new SealedObject(ser, ci);
/*    */   }
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

     
      Cipher cipher = Cipher.getInstance("Blowfish");
      AlgorithmParameters params = cipher.getParameters();
      System.out.println("Blowfish.params = "+params);
      cipher.init(Cipher.ENCRYPT_MODE, key);
      SealedObject msg = new SealedObject("This is a secret", cipher);
     
      SecretKeySpec serverKey = new SecretKeySpec(kbytes, "Blowfish");
      Cipher scipher = Cipher.getInstance("Blowfish");
      scipher.init(Cipher.DECRYPT_MODE, serverKey);
      String theMsg = (String) msg.getObject(scipher);
      System.out.println("Decrypted: "+theMsg);
     
      SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
      BigInteger bi = new BigInteger(320, rnd);
      byte[] k2bytes = bi.toByteArray();
View Full Code Here

            byte[] passwdByte = SessionPassword.char2byte(passwd);
            byte[] msg = new byte[salt.length + passwdByte.length];
            System.arraycopy(salt, 0, msg, 0, salt.length);
            System.arraycopy(passwdByte, 0, msg, salt.length, passwdByte.length);

            SealedObject encrypted = new SealedObject(msg, rsa);

            ByteArrayOutputStream db = new ByteArrayOutputStream();
            ObjectOutputStream stream = new ObjectOutputStream(db);
            stream.writeObject(encrypted);
            return db.toByteArray();
View Full Code Here

        }

        try {
            ObjectInputStream streamIn = new ObjectInputStream(
                    new ByteArrayInputStream(encryption, 0, encryption.length));
            SealedObject encrypted = (SealedObject) streamIn.readObject();

            Cipher dec = Cipher.getInstance("RSA");
            dec.init(Cipher.DECRYPT_MODE, privateKey);
            byte msg[] = (byte[]) encrypted.getObject(dec);

            int passwdLength = msg.length - salt.length;
            byte passwd[] = new byte[passwdLength];
            System.arraycopy(msg, salt.length, passwd, 0, passwdLength);
            return SessionPassword.byte2char(passwd);
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.