List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:de.thischwa.pmcms.tool.DESCryptor.java
public String decrypt(String encryptedTxt) throws CryptorException { if (encryptedTxt == null || encryptedTxt.trim().length() == 0) return null; if (key == null) key = buildKey();/*from w w w.j a v a 2 s. com*/ try { byte[] encrypedPwdBytes = Base64.decodeBase64(encryptedTxt); Cipher cipher = Cipher.getInstance(algorithm); // cipher is not thread safe cipher.init(Cipher.DECRYPT_MODE, key); byte[] plainTextPwdBytes = cipher.doFinal(encrypedPwdBytes); return new String(plainTextPwdBytes); } catch (Exception e) { throw new CryptorException(e); } }
From source file:client.communication.SocketClient.java
/** * Envia a mensagem para o servidor e retorna a resposta * //from w ww.java2s.c om * @param message * @return */ public String sendMessage(String message) { Socket socket = null; PrintStream stream = null; try { socket = new Socket(serverAddress, serverPort); stream = new PrintStream(socket.getOutputStream()); // Envia requisiao stream.println(message); // L resposta socket.getInputStream().read(response); } catch (IOException e) { System.out.println("Problem connecting server!"); } finally { try { // Fecha stream if (stream != null) stream.close(); if (socket != null) socket.close(); } catch (IOException e) { System.err.println("Problem closing socket: " + e.getMessage()); } } // Decodifica resposta em base 64 String _reply = new String(Base64.decodeBase64(response)); // Remove o espao nas extremidades da string de resposta return _reply.trim(); }
From source file:energy.usef.core.service.rest.message.EncryptionKeyEndpointTest.java
/** * Tests that the creation of a new key pair with a password returns the correct public key (encoded in Base64 for readability). *//*from w w w . j av a2s . co m*/ @Test public void testCreateNewEncryptionKeyPair() { PowerMockito.when(keystoreHelperService.createSecretKey(Matchers.eq(SEED))) .thenReturn(Base64.decodeBase64(B64_PUBLIC_KEY)); Response response = encryptionKeyService.createNewEncryptionKeyPair(SEED); assertNotNull(response); assertEquals("HTTP response code mismatch.", Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals("Public key mismatch.", B64_PUBLIC_KEY, response.getEntity().toString()); }
From source file:ch.newscron.newscronjsp.RegistrationUtils.java
public String getReward(String prevURL) { String[] urlParts = prevURL.split("/"); if (urlParts.length >= 6) { try {//from w w w. j av a 2 s . c om return new String(Base64.decodeBase64((urlParts[5]).getBytes()), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(RegistrationUtils.class.getName()).log(Level.SEVERE, null, ex); } } return " - "; }
From source file:com.alu.e3.auth.executor.HttpBasicExecutor.java
@Override public AuthReport checkAllowed(Exchange exchange, Api api) { AuthReport authReport = new AuthReport(); String authHeader = (String) exchange.getIn().getHeader("Authorization"); if (authHeader != null) { String[] chunks = authHeader.split(" "); // Only expect two parts: the auth scheme and the user/pass encoding if (chunks.length == 2) { String scheme = chunks[0]; if ("Basic".equalsIgnoreCase(scheme)) { String base64 = chunks[1]; String decoded = new String(Base64.decodeBase64(base64.getBytes())); chunks = decoded.split(":"); if (chunks.length >= 2) { String user = chunks[0]; String pass = chunks[1]; // Checks if the user is allowed to use this service authReport = dataAccess.checkAllowed(api, user, pass); } else { if (logger.isDebugEnabled()) { logger.debug("Unable to decode user/pass"); }/* w w w .j ava 2s .c o m*/ authReport.setBadRequest(true); } } else { if (logger.isDebugEnabled()) { logger.debug("Auth scheme not Basic (" + scheme + "). Cannot authenticate request"); } authReport.setBadRequest(true); } } else { if (logger.isDebugEnabled()) { logger.debug("Improperly formed authorization header:" + authHeader); } authReport.setBadRequest(true); } } else { if (logger.isDebugEnabled()) { logger.debug("Http Basic Authentication Header is missing"); } authReport.setBadRequest(true); } return authReport; }
From source file:de.alpharogroup.email.data.sources.ByteArrayDataSourceTest.java
/** * Test method for the constructor of {@link ByteArrayDataSource}. * * @throws IOException//from w w w . j a v a2 s . c o m * Signals that an I/O exception has occurred. */ @Test public void testByteArrayDataSource() throws IOException { final String expected = "Sample Data"; final DataSource dataSource = new ByteArrayDataSource(expected.getBytes(), Mimetypes.TEXT_PLAIN.getMimetype()); final DataHandler dataHandler = new DataHandler(dataSource); final String rawString = EmailExtensions.getString(dataHandler); final String actual = new String(Base64.decodeBase64(rawString)); assertEquals("Not expected content", expected, actual); }
From source file:com.bl4ckbird.ebitm.bitmessage.entities.Message.java
public String getMessage() { String decmsg = ""; try {/*from ww w. j av a 2 s. c o m*/ decmsg = new String(Base64.decodeBase64(message), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Message.class.getName()).log(Level.SEVERE, null, ex); } return decmsg; }
From source file:com.vmware.identity.rest.core.server.authorization.token.saml.SAMLTokenBuilder.java
@Override public AccessToken build(TokenInfo info) throws InvalidTokenException { String xml = new String(Base64.decodeBase64(info.getToken())); try {// w w w . j av a 2s. c o m SamlTokenImpl token = new SamlTokenImpl(xml, jaxbContext); return new SAMLToken(token); } catch (com.vmware.vim.sso.client.exception.InvalidTokenException e) { log.error("Error parsing the SAML Bearer Token", e); throw new InvalidTokenException(sm.getString("auth.ite.parse.malformed")); } }
From source file:com.alibaba.jstorm.hdfs.avro.FixedAvroSerializer.java
public FixedAvroSerializer() throws IOException, NoSuchAlgorithmException { InputStream in = this.getClass().getClassLoader().getResourceAsStream("FixedAvroSerializer.config"); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line;//from w ww. jav a 2s . co m while ((line = reader.readLine()) != null) { Schema schema = new Schema.Parser().parse(line); byte[] fp = SchemaNormalization.parsingFingerprint(FP_ALGO, schema); String fingerPrint = new String(Base64.decodeBase64(fp)); fingerprint2schemaMap.put(fingerPrint, schema); schema2fingerprintMap.put(schema, fingerPrint); } }
From source file:com.mqtt.curl.mqtt.util.Base64Util.java
/** * BASE64???/*from w w w . j a v a 2 s .com*/ * * @param base64String * @return */ public static byte[] decode(String base64String) { try { return Base64.decodeBase64(base64String.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { return null; } }