List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.sammyun.filter.AccessDeniedFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"), new String(Base64.decodeBase64("U2hvcHh4Lm5ldA=="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); }
From source file:net.oauth.jsontoken.crypto.MagicRsaPublicKey.java
private static PublicKey parseKey(String magicKey) { String[] pieces = magicKey.split(Pattern.quote(".")); if (pieces.length != 3) { throw new IllegalStateException("not a valid magic key: " + magicKey); }// w w w . j a v a 2 s .c om if (!pieces[0].equals("RSA")) { throw new IllegalStateException("unkown key type for magic key: " + pieces[0]); } String modulusString = pieces[1]; String exponentString = pieces[2]; byte[] modulusBytes = Base64.decodeBase64(modulusString); byte[] exponentBytes = Base64.decodeBase64(exponentString); BigInteger modulus = new BigInteger(modulusBytes); BigInteger exponent = new BigInteger(exponentBytes); RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent); KeyFactory fac; try { fac = KeyFactory.getInstance("RSA"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("RSA key factory missing on platform", e); } try { return fac.generatePublic(spec); } catch (InvalidKeySpecException e) { throw new IllegalStateException("bad key in descripor doc: " + magicKey, e); } }
From source file:com.alibaba.otter.shared.common.utils.ByteUtils.java
public static byte[] base64StringToBytes(String string) { try {/*from w w w . j av a 2 s. c o m*/ return Base64.decodeBase64(string.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new NestableRuntimeException(e); } }
From source file:elaborate.util.PasswordUtil.java
/** * * @param plainPassword/* w w w.j a va 2 s.co m*/ * a plain text password * @param encodedPassword * Base64 encoded MD5 hash * @return */ public static synchronized boolean matches(String plainPassword, String encodedPassword) { byte[] base64DecodedMd5Password = Base64.decodeBase64(encodedPassword.getBytes()); String base64DecodedPasswordAsString = new String(base64DecodedMd5Password, Charsets.UTF_8); byte[] md5Password = encode(plainPassword); String md5PasswordString = new String(md5Password); /* * // return MessageDigest.isEqual(md5Password, base64DecodedMd5Password); * Fix authentication by doing a string comparison instead of a byte comparison. * We can't change eLaborate Classic for now. */ return (StringUtils.equals(md5PasswordString, base64DecodedPasswordAsString)); }
From source file:com.coroptis.coidi.core.services.impl.ConvertorServiceImpl.java
@Override public byte[] convertToBytes(String s) { return Base64.decodeBase64(s.getBytes()); }
From source file:com.dv.sharer.ws.controller.ImageController.java
public String upload(Integer id, String encodedData) { byte[] data = Base64.decodeBase64(encodedData); Image binaryData = imageDao.find(id); if (binaryData == null) { String message = "No image to attach binary data to"; logger.log(Level.SEVERE, message); Response response = new Response(); response.add(message);/* w w w .j a v a2 s. co m*/ response.setResponseType(Response.ResponseType.Severe); return response.toJson(); } binaryData.setData(data); binaryData = imageDao.update(binaryData); Response response = new Response(); response.setPayload(binaryData.getId_value().toString()); response.setResponseType(Response.ResponseType.Info); return response.toJson(); }
From source file:com.eviware.loadui.util.serialization.SerializationUtils.java
public static Object deserialize(String base64String) throws ClassNotFoundException, IOException { if (base64String == null) return null; return deserialize(Base64.decodeBase64(base64String)); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoDigestService.java
public String sha1Base64(String dataB64) { validateB64(dataB64); return Base64.encodeBase64String(DigestUtils.sha1(Base64.decodeBase64(dataB64))); }
From source file:com.mnr.java.intellij.idea.plugin.base64helper.DecoderPopupItem.java
@Override public String encodeDecode(String selectedText) { return new String(Base64.decodeBase64(selectedText)); }
From source file:com.amazonaws.cognito.devauthsample.AESEncryption.java
/** * Decrypt a string with given key./*w w w .j a v a 2s . co m*/ * * @param cipherText encrypted string * @param key the key used in decryption * @return a decrypted string */ public static String unwrap(String cipherText, String key) { byte[] dataToDecrypt = Base64.decodeBase64(cipherText.getBytes()); byte[] iv = new byte[16]; byte[] data = new byte[dataToDecrypt.length - 16]; System.arraycopy(dataToDecrypt, 0, iv, 0, 16); System.arraycopy(dataToDecrypt, 16, data, 0, dataToDecrypt.length - 16); byte[] plainText = decrypt(data, key, iv); return new String(plainText); }