List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.aqnote.shared.cryptology.cert.util.KeyStoreUtil.java
public static KeyStore coverString2KeyStore(String base64PKS, String password) throws CertException { byte[] keyStoreByte = Base64.decodeBase64(base64PKS); InputStream istream = StreamUtil.bytes2Stream(keyStoreByte); try {/* w w w. j a va 2 s . co m*/ KeyStore keyStore = KeyStore.getInstance(PKCS12_STORE_TYPE); keyStore.load(istream, password.toCharArray()); istream.close(); return keyStore; } catch (KeyStoreException e) { throw new CertException(e); } catch (NoSuchAlgorithmException e) { throw new CertException(e); } catch (CertificateException e) { throw new CertException(e); } catch (IOException e) { throw new CertException(e); } }
From source file:br.com.topsys.cd.applet.AssinaturaApplet.java
public String assinar(String dados) { String retorno = null;//from www .j a va 2s .c o m try { X509Certificado certificadoAux = new X509Certificado(Base64.decodeBase64(this.certificado)); if (certificadoAux.equals(this.certificadoDigital.getX509Certificado())) { if (super.flagListaCertificado) { Gson gson = new Gson(); Map<Long, String> map = gson.fromJson(dados, HashMap.class); for (Map.Entry<Long, String> entry : map.entrySet()) { entry.setValue(new AssinaturaDigital().assinar(this.certificadoDigital, entry.getValue())); } retorno = gson.toJson(map); } else { retorno = new AssinaturaDigital().assinar(this.certificadoDigital, dados); } } else { JOptionPane.showMessageDialog(null, "Certificado digital diferente do usurio do sistema!", "Aviso", JOptionPane.ERROR_MESSAGE); } } catch (CertificadoDigitalException | ExcecaoX509 ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Aviso", JOptionPane.ERROR_MESSAGE); this.closeError(); } return retorno; }
From source file:com.autburst.picture.Utilities.java
public static Comparator<String> getAlbumNameComparator() { return new Comparator<String>() { @Override//w ww . j av a 2s.c o m public int compare(String arg0, String arg1) { String decodeName0 = new String(Base64.decodeBase64(arg0.getBytes())); String decodeName1 = new String(Base64.decodeBase64(arg1.getBytes())); return decodeName0.compareTo(decodeName1); } }; }
From source file:ch.helmchen.camlapse.user.control.Encryption.java
private static byte[] base64Decode(String property) throws IOException { return Base64.decodeBase64(property); }
From source file:de.taimos.dvalin.jaxrs.security.basicauth.BasicAuthFilter.java
@Override protected SecurityContext handleAuthHeader(ContainerRequestContext requestContext, Message msg, String type, String auth) {/*w ww . jav a 2 s . com*/ if (auth != null && type.toLowerCase().equals("basic")) { String decoded = new String(Base64.decodeBase64(auth), Charset.forName("UTF-8")); if (!decoded.contains(":")) { return null; } String username = decoded.substring(0, decoded.indexOf(":")); String pwd = decoded.substring(decoded.indexOf(":") + 1); return this.loginUser(msg, this.basicAuthUserDAO.getUserByNameAndPassword(username, pwd)); } return null; }
From source file:com.earldouglas.xjdl.io.LicenseLoader.java
protected License decryptLicense(String encodedLicense) throws BadPaddingException, UnsupportedEncodingException, Exception { byte[] encryptedLicense = Base64.decodeBase64(encodedLicense); SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] serializedLicense = cipher.doFinal(encryptedLicense); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedLicense); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); License license = (License) objectInputStream.readObject(); objectInputStream.close();// w w w .j a v a 2s . c o m return license; }
From source file:com.security.ch08_rsa.RSACoderTextKey.java
/** * Decrypt data with provided public key * @param data base64 encoded string/*from w w w .ja v a 2s . co m*/ * @param key base64 encoded string * @return decrypted string * @throws Exception */ public static String decryptByPublicKey(String data, String key) throws Exception { byte[] result = decryptByPublicKey(Base64.decodeBase64(data), Base64.decodeBase64(key)); return new String(result, UTF_8); }
From source file:com.shenit.commons.codec.RsaUtils.java
/** * RSA??// w ww .ja v a 2 s . c o m * * @param content * ??? * @param privateKey * ? * @param input_charset * ?? * @return ?? */ public static String sign(String content, String privateKey, String algorithm, String input_charset) { try { PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)); KeyFactory keyf = KeyFactory.getInstance(CODEC_RSA); PrivateKey priKey = keyf.generatePrivate(priPKCS8); Signature signature = Signature.getInstance(algorithm); signature.initSign(priKey); signature.update(content.getBytes(input_charset)); byte[] signed = signature.sign(); return Base64Utils.base64EncodeHex(signed); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("[sign] could not sign with exception", e); } return null; }
From source file:com.opengamma.util.rest.RestUtils.java
/** * Decodes an object from base-64 such as when passed in the URI. * <p>/* w w w .ja v a 2 s.c om*/ * The conversion uses Fudge, thus the object must be convertible to/from Fudge. * * @param <T> the bean type * @param type the bean type to build, not null * @param msgBase64 the base-64 Fudge message, not null * @return the bean, not null */ public static <T> T decodeBase64(final Class<T> type, final String msgBase64) { if (msgBase64 == null) { try { return type.newInstance(); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } } byte[] msg = Base64.decodeBase64(msgBase64); FudgeContext context = OpenGammaFudgeContext.getInstance(); FudgeMsg message = context.createMessageReader(new ByteArrayInputStream(msg)).nextMessage(); if (message == null) { return null; } FudgeDeserializer deser = new FudgeDeserializer(context); return deser.fudgeMsgToObject(type, message); }
From source file:com.springcryptoutils.core.mac.Base64EncodedMacImpl.java
public String digest(String message) { return Base64.encodeBase64String(mac.digest(Base64.decodeBase64(message))); }