java.security.SignedObject Java Examples
The following examples show how to use
java.security.SignedObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LCManager.java From library with Apache License 2.0 | 6 votes |
private HashSet<CollectData> getSignedCollects(HashSet<SignedObject> signedCollects) { HashSet<CollectData> colls = new HashSet<CollectData>(); for (SignedObject so : signedCollects) { CollectData c; try { c = (CollectData) so.getObject(); int sender = c.getPid(); if (tomLayer.verifySignature(so, sender)) { colls.add(c); } } catch (IOException | ClassNotFoundException ex) { logger.error("Error processing collect data", ex); } } return colls; }
Example #2
Source File: LCManager.java From library with Apache License 2.0 | 5 votes |
/** * Keep collect from an incoming SYNC message * @param ts the current regency * @param signedCollect the signed collect data */ public void addCollect(int regency, SignedObject signedCollect) { HashSet<SignedObject> c = collects.get(regency); if (c == null) c = new HashSet<SignedObject>(); c.add(signedCollect); collects.put(regency, c); }
Example #3
Source File: MatchmakingClient.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
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); }
Example #4
Source File: Authenticator.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
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; }
Example #5
Source File: RegServlet.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
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); }
Example #6
Source File: RegServlet.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
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()); } }
Example #7
Source File: Correctness.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #8
Source File: Correctness.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #9
Source File: TOMLayer.java From library with Apache License 2.0 | 5 votes |
/** * Verifies the signature of a signed object * * @param so Signed object to be verified * @param sender Replica id that supposedly signed this object * @return True if the signature is valid, false otherwise */ public boolean verifySignature(SignedObject so, int sender) { try { return so.verify(publicKey.get(sender), engine); } catch (Exception e) { logger.error("Failed to verify object signature",e); } return false; }
Example #10
Source File: TOMLayer.java From library with Apache License 2.0 | 5 votes |
public SignedObject sign(Serializable obj) { try { return new SignedObject(obj, privateKey, engine); } catch (Exception e) { logger.error("Failed to sign object",e); return null; } }
Example #11
Source File: Correctness.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #12
Source File: Correctness.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #13
Source File: Correctness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #14
Source File: Correctness.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #15
Source File: Correctness.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #16
Source File: Correctness.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #17
Source File: Correctness.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #18
Source File: Correctness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #19
Source File: Correctness.java From hottub with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #20
Source File: Correctness.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #21
Source File: Correctness.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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"); } }
Example #22
Source File: Copy.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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"); }
Example #23
Source File: RegistrationKey.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
public final static boolean verify(PublicKey public_key, SignedObject signed_object) throws GeneralSecurityException { return signed_object.verify(public_key, Signature.getInstance(RegServiceInterface.SIGN_ALGORITHM)); }
Example #24
Source File: RegistrationClient.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
public final SignedObject getSignedRegistrationKey() { return signed_registration_key; }
Example #25
Source File: Copy.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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"); }
Example #26
Source File: Copy.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); }
Example #27
Source File: Copy.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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"); }
Example #28
Source File: LCManager.java From library with Apache License 2.0 | 4 votes |
/** * Get the quantity of stored collect information * @param regency Regency to be considered * @return quantity of stored collect information for given regency */ public int getCollectsSize(int regency) { HashSet<SignedObject> c = collects.get(regency); return c == null ? 0 : c.size(); }
Example #29
Source File: Copy.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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"); }
Example #30
Source File: Copy.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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"); }