Package javax.crypto

Examples of javax.crypto.SealedObject


        final Message message = MessageFactory.getInstance().getMessage() ;
       
        assertNull("securityContext", SecurityContext.getSecurityContext()) ;
        assertNull("message context", message.getContext().getContext(SecurityService.CONTEXT)) ;
       
        final SealedObject securityContext = SecurityContext.encryptContext(new SecurityContext()) ;
        SecurityContext.setSecurityContext(securityContext) ;
       
        assertNotNull("securityContext", SecurityContext.getSecurityContext()) ;
       
        si.deliverAsync(message) ;
View Full Code Here


        byte[] publicCred = "secret".getBytes();
        subject.getPublicCredentials().add(publicCred);

        SecurityContext securityContext = new SecurityContext(subject, 30000l);
        Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
        SealedObject sealedObject = SecurityContext.encryptContext(securityContext);
        message.getContext().setContext(SecurityService.CONTEXT, sealedObject);

        //  serialize object
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bout);
View Full Code Here

        subject.getPublicCredentials().add(publicCred);
        byte[] privateCred = "privatesecret".getBytes();
        subject.getPrivateCredentials().add(privateCred);

        SecurityContext securityContext = new SecurityContext(subject, 30000);
        SealedObject sealedObject = SecurityContext.encryptContext(securityContext);
        assertNotNull(sealedObject);

        SecurityContext decryptContext = SecurityContext.decryptContext(sealedObject);
        assertEquals( user, decryptContext.getSubject().getPrincipals().iterator().next());
  }
View Full Code Here

   */
    final void addSecurityContext(Message message)
    {
        AssertArgument.isNotNull(message, "message");

        SealedObject securityContext = SecurityContext.getSecurityContext();
        if (securityContext != null)
        {
            message.getContext().setContext(SecurityService.CONTEXT, securityContext);
        }
    }
View Full Code Here

      int length = args != null ? args.length : 0;
      for(int a = 0; a < length; a ++)
      {
         if( (args[a] instanceof SealedObject) == false )
            continue;
         SealedObject sarg = (SealedObject) args[a];
         Object arg = sarg.getObject(decryptCipher);
         args[a] = arg;
         log.debug(" Unsealed arg("+a+"): "+arg);
      }
      // We must set the arguments because args[] may be a copy
      mi.setArguments(args);

      Interceptor next = getNext();
      Object value = next.invoke(mi);
      if( value instanceof Serializable )
      {
         Serializable svalue = (Serializable) value;
         value = new SealedObject(svalue, encryptCipher);
      }
      return value;
   }
View Full Code Here

      for(int a = 0; a < length; a ++)
      {
         if( (args[a] instanceof Serializable) == false )
            continue;
         Serializable arg = (Serializable) args[a];
         SealedObject sarg = new SealedObject(arg, encryptCipher);
         args[a] = sarg;
         log.debug(" Sealed arg("+a+"): "+arg);
      }

      Interceptor next = getNext();
      Object value = next.invoke(mi);
      if( value instanceof SealedObject )
      {
         SealedObject svalue = (SealedObject) value;
         value = svalue.getObject(decryptCipher);
      }
      return value;
   }
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

            Key key = keyGen.generateKey();
            Cipher c = Cipher.getInstance("DES/ECB/PKCS5Padding", provider);

            c.init(Cipher.ENCRYPT_MODE, key);
            String object = "Hello world";
            SealedObject so = new SealedObject(object, c);
            c.init(Cipher.DECRYPT_MODE, key);

            Object o = so.getObject(c);
            if (!o.equals(object))
            {
                return new SimpleTestResult(false, "Result object 1 not equal"
                        + "orig: " + object + " res: " + o);
            }

            o = so.getObject(key);
            if (!o.equals(object))
            {
                return new SimpleTestResult(false, "Result object 2 not equal"
                        + "orig: " + object + " res: " + o);
            }

            o = so.getObject(key, provider);
            if (!o.equals(object))
            {
                return new SimpleTestResult(false, "Result object 3 not equal"
                        + "orig: " + object + " res: " + o);
            }
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

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.