List of usage examples for org.bouncycastle.util Arrays areEqual
public static boolean areEqual(short[] a, short[] b)
From source file:com.mirth.connect.server.servlets.WebStartServlet.java
License:Open Source License
private Document getAdministratorJnlp(HttpServletRequest request) throws Exception { InputStream is = ResourceUtil.getResourceStream(this.getClass(), "mirth-client.jnlp"); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is); IOUtils.closeQuietly(is);/*from w ww. j a v a 2 s .c o m*/ Element jnlpElement = document.getDocumentElement(); // Change the title to include the version of Mirth Connect PropertiesConfiguration versionProperties = new PropertiesConfiguration(); versionProperties.setDelimiterParsingDisabled(true); versionProperties.load(ResourceUtil.getResourceStream(getClass(), "version.properties")); String version = versionProperties.getString("mirth.version"); Element informationElement = (Element) jnlpElement.getElementsByTagName("information").item(0); Element title = (Element) informationElement.getElementsByTagName("title").item(0); String titleText = title.getTextContent() + " " + version; // If a server name is set, prepend the application title with it String serverName = configurationController.getServerSettings().getServerName(); if (StringUtils.isNotBlank(serverName)) { titleText = serverName + " - " + titleText; } title.setTextContent(titleText); String scheme = request.getScheme(); String serverHostname = request.getServerName(); int serverPort = request.getServerPort(); String contextPath = request.getContextPath(); String codebase = scheme + "://" + serverHostname + ":" + serverPort + contextPath; PropertiesConfiguration mirthProperties = new PropertiesConfiguration(); mirthProperties.setDelimiterParsingDisabled(true); mirthProperties.load(ResourceUtil.getResourceStream(getClass(), "mirth.properties")); String server = null; if (StringUtils.isNotBlank(mirthProperties.getString("server.url"))) { server = mirthProperties.getString("server.url"); } else { int httpsPort = mirthProperties.getInt("https.port", 8443); String contextPathProp = mirthProperties.getString("http.contextpath", ""); // Add a starting slash if one does not exist if (!contextPathProp.startsWith("/")) { contextPathProp = "/" + contextPathProp; } // Remove a trailing slash if one exists if (contextPathProp.endsWith("/")) { contextPathProp = contextPathProp.substring(0, contextPathProp.length() - 1); } server = "https://" + serverHostname + ":" + httpsPort + contextPathProp; } jnlpElement.setAttribute("codebase", codebase); Element resourcesElement = (Element) jnlpElement.getElementsByTagName("resources").item(0); String maxHeapSize = request.getParameter("maxHeapSize"); if (StringUtils.isBlank(maxHeapSize)) { maxHeapSize = mirthProperties.getString("administrator.maxheapsize"); } if (StringUtils.isNotBlank(maxHeapSize)) { Element j2se = (Element) resourcesElement.getElementsByTagName("j2se").item(0); j2se.setAttribute("max-heap-size", maxHeapSize); } List<String> defaultClientLibs = new ArrayList<String>(); defaultClientLibs.add("mirth-client.jar"); defaultClientLibs.add("mirth-client-core.jar"); defaultClientLibs.add("mirth-crypto.jar"); defaultClientLibs.add("mirth-vocab.jar"); for (String defaultClientLib : defaultClientLibs) { Element jarElement = document.createElement("jar"); jarElement.setAttribute("download", "eager"); jarElement.setAttribute("href", "webstart/client-lib/" + defaultClientLib); if (defaultClientLib.equals("mirth-client.jar")) { jarElement.setAttribute("main", "true"); } resourcesElement.appendChild(jarElement); } List<String> clientLibs = ControllerFactory.getFactory().createExtensionController().getClientLibraries(); for (String clientLib : clientLibs) { if (!defaultClientLibs.contains(clientLib)) { Element jarElement = document.createElement("jar"); jarElement.setAttribute("download", "eager"); jarElement.setAttribute("href", "webstart/client-lib/" + clientLib); resourcesElement.appendChild(jarElement); } } List<MetaData> allExtensions = new ArrayList<MetaData>(); allExtensions .addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values()); allExtensions .addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values()); // we are using a set so that we don't have duplicates Set<String> extensionPathsToAddToJnlp = new HashSet<String>(); for (MetaData extension : allExtensions) { if (doesExtensionHaveClientOrSharedLibraries(extension)) { extensionPathsToAddToJnlp.add(extension.getPath()); } } for (String extensionPath : extensionPathsToAddToJnlp) { Element extensionElement = document.createElement("extension"); extensionElement.setAttribute("href", "webstart/extensions/" + extensionPath + ".jnlp"); resourcesElement.appendChild(extensionElement); } Element applicationDescElement = (Element) jnlpElement.getElementsByTagName("application-desc").item(0); Element serverArgumentElement = document.createElement("argument"); serverArgumentElement.setTextContent(server); applicationDescElement.appendChild(serverArgumentElement); Element versionArgumentElement = document.createElement("argument"); versionArgumentElement.setTextContent(version); applicationDescElement.appendChild(versionArgumentElement); String[] protocols = configurationController.getHttpsClientProtocols(); String[] cipherSuites = configurationController.getHttpsCipherSuites(); // Only add arguments for the protocols / cipher suites if they are non-default if (!Arrays.areEqual(protocols, MirthSSLUtil.DEFAULT_HTTPS_CLIENT_PROTOCOLS) || !Arrays.areEqual(cipherSuites, MirthSSLUtil.DEFAULT_HTTPS_CIPHER_SUITES)) { Element sslArgumentElement = document.createElement("argument"); sslArgumentElement.setTextContent("-ssl"); applicationDescElement.appendChild(sslArgumentElement); Element protocolsArgumentElement = document.createElement("argument"); protocolsArgumentElement.setTextContent(StringUtils.join(protocols, ',')); applicationDescElement.appendChild(protocolsArgumentElement); Element cipherSuitesArgumentElement = document.createElement("argument"); cipherSuitesArgumentElement.setTextContent(StringUtils.join(cipherSuites, ',')); applicationDescElement.appendChild(cipherSuitesArgumentElement); } return document; }
From source file:com.password.locker.cypto.test.SecureCryptoTest.java
License:Open Source License
/** * Main test.//from w w w.j av a 2 s. c om * @throws NoSuchPaddingException * @throws NoSuchProviderException * @throws NoSuchAlgorithmException * @throws InvalidAlgorithmParameterException * @throws InvalidKeyException */ @Test public final void testEncryptBytes() throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException { byte[] data = { (byte) 0x1, (byte) 0x1, (byte) 0x1, (byte) 0x1, (byte) 0x1 }; byte[] enc = secImpl.encrypt(data); byte[] plain = secImpl.decrypt(enc); assertTrue(Arrays.areEqual(plain, data)); assertFalse(Arrays.areEqual(plain, enc)); }
From source file:com.raphfrk.craftproxyclient.net.protocol.p16x.P16xProtocol.java
License:Open Source License
private byte[] decryptSecret(AsymmetricCipherKeyPair RSAKeyPair, P16xEncryptionKeyResponse response, PacketChannel client, byte[] token) throws IOException { AsymmetricBlockCipher rsa = new PKCS1Encoding(new RSAEngine()); AsymmetricKeyParameter privateKey = RSAKeyPair.getPrivate(); rsa.init(false, privateKey);// www.jav a2 s . c o m byte[] decryptedSecret; byte[] decryptedToken; try { decryptedSecret = rsa.processBlock(response.getEncryptedSecret(), 0, response.getEncryptedSecret().length); } catch (InvalidCipherTextException e) { sendKick("Unable to encrypt shared secret " + e.getMessage(), client); return null; } try { decryptedToken = rsa.processBlock(response.getToken(), 0, response.getToken().length); } catch (InvalidCipherTextException e) { sendKick("Unable to encrypt token " + e.getMessage(), client); return null; } if (!Arrays.areEqual(token, decryptedToken)) { sendKick("Decrypted token mismatch", client); return null; } return decryptedSecret; }
From source file:com.zotoh.core.io.JUT.java
License:Open Source License
@Test public void testBytesStreamData() throws Exception { StreamData s = new StreamData(); String data = "hello world"; s.resetMsgContent(data);/*ww w . ja v a 2 s .c o m*/ assertTrue(s.getMsgContent() == s.getBin()); assertTrue(s.getBytes() == s.getBin()); assertTrue(s.getSize() == asBytes(data).length); assertFalse(s.isZiped()); assertTrue(Arrays.areEqual(s.getBin(), asBytes(data))); }
From source file:com.zotoh.core.io.JUT.java
License:Open Source License
@Test public void testLargeBytesStreamData() throws Exception { StreamData s = new StreamData(); StringBuilder b = new StringBuilder(4000000); for (int i = 0; i < 5000000; ++i) { b.append("x"); }//from w ww . j av a 2 s. c om byte[] bits = b.toString().getBytes("UTF-8"); s.resetMsgContent(b); assertTrue(s.getMsgContent() != s.getBin()); assertTrue(s.getBytes() != s.getBin()); assertTrue(s.getSize() == bits.length); assertTrue(s.isZiped()); assertTrue(Arrays.areEqual(s.getBin(), bits)); }
From source file:com.zotoh.core.io.JUT.java
License:Open Source License
@Test public void testStreamStreamData() throws Exception { StreamData s = new StreamData(); String data = "hello world"; s.resetMsgContent(data);/* w w w.ja va 2 s .co m*/ assertTrue(s.getStream() instanceof ByteArrayInputStream); assertTrue(Arrays.areEqual(getBytes(s.getStream()), asBytes(data))); }
From source file:com.zotoh.core.io.JUT.java
License:Open Source License
@Test public void testFileStreamData() throws Exception { StreamData s = StreamUte.createFileSData(); OutputStream os = new FileOutputStream(s.getFileRef()); File fout = s.getFileRef();/*from ww w.j a v a 2s . c om*/ String data = "hello world"; os.write(asBytes(data)); os.close(); try { assertTrue(s.getStream() instanceof SmartFileInputStream); assertTrue(Arrays.areEqual(getBytes(s.getStream()), asBytes(data))); assertTrue(Arrays.areEqual(s.getBytes(), asBytes(data))); assertTrue(s.getBin() == null); assertTrue(s.getSize() == data.length()); } finally { FileUte.delete(fout); } }
From source file:core.database.online.OnlineDatabase.java
@Override public boolean validatePassword(String salt, String pass, String key) { System.out.println(pass);/*from ww w.j a v a 2s . c om*/ pass = getPasswordForDatabase(salt, pass); System.out.println(pass); System.out.println(key); System.out.println(Arrays.areEqual(pass.getBytes(), key.getBytes())); return Arrays.areEqual(pass.getBytes(), key.getBytes()); }
From source file:de.afarber.tlspskclient2.MockPSKTlsClient.java
License:Open Source License
@Override public void notifyHandshakeComplete() throws IOException { super.notifyHandshakeComplete(); TlsSession newSession = context.getResumableSession(); if (newSession != null) { byte[] newSessionID = newSession.getSessionID(); String hex = Hex.toHexString(newSessionID); if (this.session != null && Arrays.areEqual(this.session.getSessionID(), newSessionID)) { System.out.println("Resumed session: " + hex); } else {//from w ww .j a v a 2s. c o m System.out.println("Established session: " + hex); } this.session = newSession; } }
From source file:de.burlov.bouncycastle.io.test.EncryptOutputStreamTest.java
License:Apache License
@Test public void testEncryptDecrypt() throws IOException { BlockCipher cipher = new SerpentEngine(); Random rnd = new Random(); byte[] key = new byte[256 / 8]; rnd.nextBytes(key);// w w w . j a va2 s. com byte[] iv = new byte[cipher.getBlockSize()]; rnd.nextBytes(iv); byte[] data = new byte[1230000]; new Random().nextBytes(data); ByteArrayOutputStream bout = new ByteArrayOutputStream(); CryptOutputStream eout = new CryptOutputStream(bout, cipher, key); eout.write(data); eout.close(); byte[] eData = bout.toByteArray(); // eData[1000] = (byte) (eData[1000] & 0x88); ByteArrayInputStream bin = new ByteArrayInputStream(eData); CryptInputStream din = new CryptInputStream(bin, cipher, key); bout = new ByteArrayOutputStream(); IOUtils.copy(din, bout); eData = bout.toByteArray(); Assert.assertTrue(Arrays.areEqual(data, eData)); }