List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:aajavafx.Kripto.java
public String decrypt(String cipherText) throws Exception { Base64 decoder = new Base64(); byte[] decodedBytes = org.apache.commons.codec.binary.Base64.decodeBase64(cipherText.getBytes()); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES"); cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV.getBytes("UTF-8"))); return new String(cipher.doFinal(decodedBytes), "UTF-8"); }
From source file:mx.bigdata.sat.cfdi.CFDv3Debugger.java
private void dumpDigests() throws Exception { System.err.println(cfd.getCadenaOriginal()); String certStr = cfd.document.getCertificado(); Base64 b64 = new Base64(); byte[] cbs = b64.decode(certStr); X509Certificate cert = (X509Certificate) KeyLoaderFactory .createInstance(KeyLoaderEnumeration.PUBLIC_KEY_LOADER, new ByteArrayInputStream(cbs)).getKey(); cert.checkValidity();// w ww. ja v a2 s . co m String sigStr = cfd.document.getSello(); byte[] signature = b64.decode(sigStr); CFDv3.dump("Digestion firmada", signature, System.err); Cipher dec = Cipher.getInstance("RSA"); dec.init(Cipher.DECRYPT_MODE, cert); byte[] result = dec.doFinal(signature); CFDv3.dump("Digestion decriptada", result, System.err); ASN1InputStream aIn = new ASN1InputStream(result); ASN1Sequence seq = (ASN1Sequence) aIn.readObject(); ASN1OctetString sigHash = (ASN1OctetString) seq.getObjectAt(1); CFDv3.dump("Sello", sigHash.getOctets(), System.err); }
From source file:biblivre3.utils.TextUtils.java
public static String encodePassword(String password) { if (password == null) { throw new ExceptionUser("Password is null"); }/*from ww w . j a v a2 s .c o m*/ if (password.trim().length() == 0) { throw new ExceptionUser("Password is empty"); } try { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(password.getBytes("UTF-8")); byte[] raw = md.digest(); return new String((new Base64()).encode(raw)); } catch (Exception e) { throw new ExceptionUser(e.getMessage()); } }
From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java
public static String toBase64Image(BufferedImage bimg) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from w w w . ja v a2 s .c o m ImageIO.write(bimg, "png", baos); } catch (IOException e) { e.printStackTrace(); } return new Base64().encodeToString(baos.toByteArray()); }
From source file:de.hybris.platform.b2b.punchout.services.impl.SymmetricManager.java
public static String decrypt(final String encrypted, final String key) throws PunchOutCipherException { String decrypted = null;//from w w w. j a v a 2 s .com try { final Key skeySpec = new SecretKeySpec(new Base64().decode(key), ALGORITHM); final Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, skeySpec); final byte[] decodedValue = new Base64().decode(encrypted.getBytes()); final byte[] decryptedValue = cipher.doFinal(decodedValue); decrypted = new String(decryptedValue); } catch (final NoSuchAlgorithmException | NoSuchPaddingException e) { // should never happen LOG.error("System was unable instantiate Cipher.", e); } catch (InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) { final String msg = "Error occured during decryption." + e.getMessage(); LOG.info(msg); throw new PunchOutCipherException(msg, e); } return decrypted; }
From source file:com.apifest.oauth20.AuthChecks.java
protected String getBasicAuthenticationClientId(HttpRequest req) { // extract Basic Authentication header String authHeader = req.headers().get(HttpHeaders.AUTHORIZATION); String clientId = null;/* w w w . j a v a2s. co m*/ if (authHeader != null && authHeader.contains(BASIC)) { String value = authHeader.replace(BASIC, ""); Base64 decoder = new Base64(); byte[] decodedBytes = decoder.decode(value); String decoded = new String(decodedBytes); // client_id:client_secret String[] str = decoded.split(":"); if (str.length == 2) { String authClientId = str[0]; String authClientSecret = str[1]; // check valid - DB call if (db.validClient(authClientId, authClientSecret)) { clientId = authClientId; } } } return clientId; }
From source file:jeeves.utils.BLOB.java
public static Element encode(int responseCode, byte blob[], String contentType, String filename) { Element response = new Element("response"); response.setAttribute("responseCode", responseCode + ""); response.setAttribute("contentType", contentType); response.setAttribute("contentLength", blob.length + ""); if (filename != null) response.setAttribute("contentDisposition", "attachment;filename=" + filename); //String data = new BASE64Encoder().encode(blob); String data = new String(new Base64().encode(blob), Charset.forName("UTF-8")); response.setText(data);/*ww w . jav a 2 s. c o m*/ return response; }
From source file:mx.bigdata.cfdi.CFDv3Debugger.java
public void dumpDigests() throws Exception { System.err.println(cfd.getOriginalString()); byte[] digest = cfd.getDigest(); CFDv3.dump("Digestion generada", digest, System.err); String certStr = cfd.document.getCertificado(); Base64 b64 = new Base64(); byte[] cbs = b64.decode(certStr); X509Certificate cert = KeyLoader.loadX509Certificate(new ByteArrayInputStream(cbs)); cert.checkValidity();/*from w w w .j av a 2 s. c om*/ String sigStr = cfd.document.getSello(); byte[] signature = b64.decode(sigStr); CFDv3.dump("Digestion firmada", signature, System.err); Cipher dec = Cipher.getInstance("RSA"); dec.init(Cipher.DECRYPT_MODE, cert); byte[] result = dec.doFinal(signature); CFDv3.dump("Digestion decriptada", result, System.err); ASN1InputStream aIn = new ASN1InputStream(result); ASN1Sequence seq = (ASN1Sequence) aIn.readObject(); ASN1OctetString sigHash = (ASN1OctetString) seq.getObjectAt(1); CFDv3.dump("Sello", sigHash.getOctets(), System.err); }
From source file:model.Encryption.java
/** * * @param encryptedText/*from w ww .j a v a 2 s . c o m*/ * @return * @throws Exception */ @SuppressWarnings("static-access") public String decrypt(String encryptedText) throws Exception { if (secret == null) generateSecretKey(); byte[] encryptedTextBytes = new Base64().decode(encryptedText); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, secret); byte[] decryptedTextBytes = cipher.doFinal(encryptedTextBytes); return new String(decryptedTextBytes, "UTF-8"); }
From source file:com.alfaariss.oa.authentication.password.digest.HtPasswdSHA1Digest.java
/** * @see CryptoDigest#digest(java.lang.String, java.lang.String, java.lang.String) *//*from w w w. j a v a2 s. c o m*/ @Override public byte[] digest(String password, String realm, String username) throws OAException { byte[] sha1_bytes = super.digest(password, realm, username); Base64 b = new Base64(); byte[] sha1 = b.encode(sha1_bytes); byte[] result = new byte[sha1.length + 5]; System.arraycopy("{SHA}".getBytes(), 0, result, 0, 5); System.arraycopy(sha1, 0, result, 5, sha1.length); return result; }