Java 类java.security.SignedObject 实例源码

项目:jdk8u-jdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:openjdk-jdk10    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:openjdk9    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:jdk8u_jdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:infobip-open-jdk-8    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:jdk8u-dev-jdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:tribaltrouble    文件:RegServlet.java   
public final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String request_key_str = normalizeKey(req.getParameter("key"));
        String affiliate_id = req.getParameter("affiliate_id");
        String current_affiliate_id = req.getParameter("current_affiliate_id");
        int version = parseInt(req.getParameter("version"), 0);
        boolean timelimit = parseBoolean(req.getParameter("timelimit"));
        int maxtime = parseInt(req.getParameter("maxtime"), 0);
        boolean forcequit = parseBoolean(req.getParameter("forcequit"));
        int maxgames = parseInt(req.getParameter("maxgames"), 0);

log("Oddlabs: got key request: remote host = " + req.getRemoteHost() + " | key_str = " + request_key_str + " | current_affiliate_id = " + current_affiliate_id + " | affiliate_id = " + affiliate_id + " | version = " + version + " | timelimit = " + timelimit + " | maxtime = " + maxtime + " | forcequit = " + forcequit + " | maxgames = " + maxgames);

        String key_str = createKey(request_key_str, current_affiliate_id);
        long key = RegistrationKey.decode(key_str);
        try {
            SignedObject signed_registration = register(new RegistrationRequest(key, affiliate_id, version, timelimit, maxtime, forcequit, maxgames));
            res.setContentType("application/octet-stream");

            ServletOutputStream out = res.getOutputStream();
            ObjectOutputStream obj_out = new ObjectOutputStream(out);
            obj_out.writeObject(signed_registration);
            obj_out.close();
            log("Oddlabs: Registered key: " + key_str);
        } catch (Exception e) {
            log("got exception while registering: " + e);
            res.sendError(500, e.toString());
        }
    }
项目:tribaltrouble    文件:RegServlet.java   
private SignedObject register(RegistrationRequest reg_request) throws SQLException, ServletException {
    long reg_key = reg_request.getKey();
    String affiliate_id = reg_request.getAffiliate();
    String encoded_key = RegistrationKey.encode(reg_key);
    RegistrationInfo reg_info = DBInterface.registerKey(getDataSource(), reg_request);
    return sign(reg_info);
}
项目:tribaltrouble    文件:Authenticator.java   
private final String checkKey(SignedObject reg_key) {
    String reg_code = null;
    if (reg_key != null) {
        try {
            if (RegistrationKey.verify(server.getPublicRegKey(), reg_key)) {
                // This cast should not fail, because we signed it and the signature checked out ok
                RegistrationInfo reg_info = (RegistrationInfo)reg_key.getObject();
                reg_code = RegistrationKey.encode(reg_info.getKey());
            }
        } catch (Exception e) {
            MatchmakingServer.getLogger().warning("Could not verify signature because of: " + e.getMessage());
        }
    }
    return reg_code;
}
项目:tribaltrouble    文件:MatchmakingClient.java   
public final void connected(AbstractConnection connection) {
        SignedObject signed_key = Renderer.getRegistrationClient().getSignedRegistrationKey();
        Connection wrapped_connection = (Connection)conn.getWrappedConnection();
        matchmaking_login_interface.setLocalRemoteAddress(wrapped_connection.getLocalAddress());
System.out.println("wrapped_connection.getLocalAddress()     = " + wrapped_connection.getLocalAddress() );
        int revision = LocalInput.getRevision();
        if (!Renderer.isRegistered())
            matchmaking_login_interface.loginAsGuest(revision);
        else if (login_details != null)
            matchmaking_login_interface.createUser(login, login_details, signed_key, revision);
        else
            matchmaking_login_interface.login(login, signed_key, revision);
    }
项目:jdk7-jdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:openjdk-source-code-learn    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:OLD-OpenJDK8    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:JAVA_UNIT    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:openjdk-jdk7u-jdk    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:openjdk-icedtea7    文件:Correctness.java   
public static void main(String[] args) throws Exception {

        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");
        }
    }
项目:proactive-component-monitoring    文件:SigningEngine.java   
public Object signObject(Serializable object, PrivateKey privateKey) {
    try {
        return new SignedObject(object, privateKey, signingEngine);
    } catch (Exception e) {
        System.out.println("Exception in object signature : " + e);
        System.out.println(privateKey);
        e.printStackTrace();
    }

    return null;
}
项目:proactive-component-monitoring    文件:SigningEngine.java   
public boolean checkSignature(Object signedObject, PublicKey publicKey) {
    try {
        if (((SignedObject) signedObject).verify(publicKey, signingEngine)) {
            return true;
        }
    } catch (Exception e) {
        System.out.println("Exception object signature checking :" + e);
        e.printStackTrace();
    }

    return false;
}
项目:jdk8u-jdk    文件:Copy.java   
public static void main(String args[]) throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    KeyPair kp = kg.genKeyPair();

    Signature signature = Signature.getInstance(DSA);
    Test original = new Test();
    SignedObject so = new SignedObject(original, kp.getPrivate(),
            signature);
    System.out.println("Signature algorithm: " + so.getAlgorithm());

    signature = Signature.getInstance(DSA, "SUN");
    if (!so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Verification failed");
    }

    kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    kp = kg.genKeyPair();

    if (so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Unexpected success");
    }

    Object copy = so.getObject();
    if (!original.equals(copy)) {
        throw new RuntimeException("Signed object is not equal "
                + "to original one: " + copy);
    }

    /*
     * The signed object is a copy of an original one.
     * Once the copy is made, further manipulation
     * of the original object shouldn't has any effect on the copy.
     */
    original.set(MAGIC - 1);
    copy = so.getObject();
    if (original.equals(copy)) {
        throw new RuntimeException("Signed object is not a copy "
                + "of original one: " + copy);
    }

    System.out.println("Test passed");
}
项目:openjdk-jdk10    文件:Copy.java   
public static void main(String args[]) throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    KeyPair kp = kg.genKeyPair();

    Signature signature = Signature.getInstance(DSA);
    Test original = new Test();
    SignedObject so = new SignedObject(original, kp.getPrivate(),
            signature);
    System.out.println("Signature algorithm: " + so.getAlgorithm());

    signature = Signature.getInstance(DSA, "SUN");
    if (!so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Verification failed");
    }

    kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    kp = kg.genKeyPair();

    if (so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Unexpected success");
    }

    Object copy = so.getObject();
    if (!original.equals(copy)) {
        throw new RuntimeException("Signed object is not equal "
                + "to original one: " + copy);
    }

    /*
     * The signed object is a copy of an original one.
     * Once the copy is made, further manipulation
     * of the original object shouldn't has any effect on the copy.
     */
    original.set(MAGIC - 1);
    copy = so.getObject();
    if (original.equals(copy)) {
        throw new RuntimeException("Signed object is not a copy "
                + "of original one: " + copy);
    }

    System.out.println("Test passed");
}
项目:openjdk9    文件:Copy.java   
public static void main(String args[]) throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    KeyPair kp = kg.genKeyPair();

    Signature signature = Signature.getInstance(DSA);
    Test original = new Test();
    SignedObject so = new SignedObject(original, kp.getPrivate(),
            signature);
    System.out.println("Signature algorithm: " + so.getAlgorithm());

    signature = Signature.getInstance(DSA, "SUN");
    if (!so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Verification failed");
    }

    kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    kp = kg.genKeyPair();

    if (so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Unexpected success");
    }

    Object copy = so.getObject();
    if (!original.equals(copy)) {
        throw new RuntimeException("Signed object is not equal "
                + "to original one: " + copy);
    }

    /*
     * The signed object is a copy of an original one.
     * Once the copy is made, further manipulation
     * of the original object shouldn't has any effect on the copy.
     */
    original.set(MAGIC - 1);
    copy = so.getObject();
    if (original.equals(copy)) {
        throw new RuntimeException("Signed object is not a copy "
                + "of original one: " + copy);
    }

    System.out.println("Test passed");
}
项目:jdk8u_jdk    文件:Copy.java   
public static void main(String args[]) throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    KeyPair kp = kg.genKeyPair();

    Signature signature = Signature.getInstance(DSA);
    Test original = new Test();
    SignedObject so = new SignedObject(original, kp.getPrivate(),
            signature);
    System.out.println("Signature algorithm: " + so.getAlgorithm());

    signature = Signature.getInstance(DSA, "SUN");
    if (!so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Verification failed");
    }

    kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    kp = kg.genKeyPair();

    if (so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Unexpected success");
    }

    Object copy = so.getObject();
    if (!original.equals(copy)) {
        throw new RuntimeException("Signed object is not equal "
                + "to original one: " + copy);
    }

    /*
     * The signed object is a copy of an original one.
     * Once the copy is made, further manipulation
     * of the original object shouldn't has any effect on the copy.
     */
    original.set(MAGIC - 1);
    copy = so.getObject();
    if (original.equals(copy)) {
        throw new RuntimeException("Signed object is not a copy "
                + "of original one: " + copy);
    }

    System.out.println("Test passed");
}
项目:lookaside_java-1.8.0-openjdk    文件:Copy.java   
public static void main(String args[]) throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    KeyPair kp = kg.genKeyPair();

    Signature signature = Signature.getInstance(DSA);
    Test original = new Test();
    SignedObject so = new SignedObject(original, kp.getPrivate(),
            signature);
    System.out.println("Signature algorithm: " + so.getAlgorithm());

    signature = Signature.getInstance(DSA, "SUN");
    if (!so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Verification failed");
    }

    kg = KeyPairGenerator.getInstance(DSA);
    kg.initialize(KEY_SIZE);
    kp = kg.genKeyPair();

    if (so.verify(kp.getPublic(), signature)) {
        throw new RuntimeException("Unexpected success");
    }

    Object copy = so.getObject();
    if (!original.equals(copy)) {
        throw new RuntimeException("Signed object is not equal "
                + "to original one: " + copy);
    }

    /*
     * The signed object is a copy of an original one.
     * Once the copy is made, further manipulation
     * of the original object shouldn't has any effect on the copy.
     */
    original.set(MAGIC - 1);
    copy = so.getObject();
    if (original.equals(copy)) {
        throw new RuntimeException("Signed object is not a copy "
                + "of original one: " + copy);
    }

    System.out.println("Test passed");
}
项目:tribaltrouble    文件:RegistrationClient.java   
public final SignedObject getSignedRegistrationKey() {
    return signed_registration_key;
}
项目:tribaltrouble    文件:RegistrationKey.java   
public final static boolean verify(PublicKey public_key, SignedObject signed_object) throws GeneralSecurityException {
    return signed_object.verify(public_key, Signature.getInstance(RegServiceInterface.SIGN_ALGORITHM));
}
项目:tribaltrouble    文件:MatchmakingServerLoginInterface.java   
public void createUser(Login login, LoginDetails login_details, SignedObject reg_key, int revision);
项目:tribaltrouble    文件:RegClientInterface.java   
public void registrationCompleted(SignedObject reg_info);