Package java.security

Examples of java.security.SignedObject


    }
      prop = new Properties();
      prop.put("aaa", "bbb");
      Object o = null;
      try {
        o = new SignedObject(prop, tkp.getPrivate(), sig);
      } catch (IOException e) {
             fail(e.toString())
      } catch (SignatureException e) {  
             fail(e.toString())
      } catch (InvalidKeyException e) {
View Full Code Here


    }
       return new Object[] { o };
    }

    public void assertDeserialized(Serializable oref, Serializable otest) {
      SignedObject ref = (SignedObject) oref;
      SignedObject test = (SignedObject) otest;

      assertEquals(test.getAlgorithm(), ref.getAlgorithm());
        try {
            assertEquals(test.getObject(), prop);       
        } catch (ClassNotFoundException e) {
             fail(e.toString())
        } catch (IOException e) {
             fail(e.toString())
        }
        try {
          if (!test.verify(tkp.getPublic(), sig)) {
              fail("verify() failed");
           
        } catch (SignatureException e) {
          fail(e.toString());       
        } catch (InvalidKeyException e) {
View Full Code Here

            return;
        }
        prop = new Properties();
        prop.put("aaa", "bbb");

        SignedObject so = new SignedObject(prop, tkp.getPrivate(), sig);

        assertEquals("SHA1withDSA", so.getAlgorithm());
        assertEquals(prop, so.getObject());

        assertTrue("verify() failed", so.verify(tkp.getPublic(), sig));

        assertNotNull("signature is null", so.getSignature());
    }
View Full Code Here

    }
      prop = new Properties();
      prop.put("aaa", "bbb");
      Object o = null;
      try {
        o = new SignedObject(prop, tkp.getPrivate(), sig);
      } catch (IOException e) {
             fail(e.toString())
      } catch (SignatureException e) {  
             fail(e.toString())
      } catch (InvalidKeyException e) {
View Full Code Here

    }
       return new Object[] { o };
    }

    public void assertDeserialized(Serializable oref, Serializable otest) {
      SignedObject ref = (SignedObject) oref;
      SignedObject test = (SignedObject) otest;

      assertEquals(test.getAlgorithm(), ref.getAlgorithm());
        try {
            assertEquals(test.getObject(), prop);       
        } catch (ClassNotFoundException e) {
             fail(e.toString())
        } catch (IOException e) {
             fail(e.toString())
        }
        try {
          if (!test.verify(tkp.getPublic(), sig)) {
              fail("verify() failed");
           
        } catch (SignatureException e) {
          fail(e.toString());       
        } catch (InvalidKeyException e) {
View Full Code Here

        String SIGALG = "SHA1withRSA";
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        KeyPair kp = kpg.generateKeyPair();

        SignedObject so1 = new SignedObject("Hello", kp.getPrivate(),
                Signature.getInstance(SIGALG));

        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(so1);
        out.close();

        byte[] data = byteOut.toByteArray();

        SignedObject so2 = (SignedObject)new ObjectInputStream(
                new ByteArrayInputStream(data)).readObject();

        if (!so2.getObject().equals("Hello")) {
            throw new Exception("Content changed");
        }
        if (!so2.getAlgorithm().equals(SIGALG)) {
            throw new Exception("Signature algorithm unknown");
        }
        if (!so2.verify(kp.getPublic(), Signature.getInstance(SIGALG))) {
            throw new Exception("Not verified");
        }
    }
View Full Code Here

TOP

Related Classes of java.security.SignedObject

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.