List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.meta.AbstractSequenceMetaDataFeatureGenerator.java
@SuppressWarnings("unchecked") public static List<String> decodeFromString(String featureValue) throws TextClassificationException { if (featureValue == null || featureValue.isEmpty()) { throw new TextClassificationException( "MetaData feature value is empty. Maybe " + "you forgot to add the feature generator " + AbstractSequenceMetaDataFeatureGenerator.class.getName()); }// w w w. j av a 2 s . c o m try { byte[] bytes = Base64.decodeBase64(featureValue); ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)); return (List<String>) objectInputStream.readObject(); } catch (IOException | ClassNotFoundException e) { throw new TextClassificationException(e); } }
From source file:com.cloudera.science.quince.VariantContextToVariantFn.java
@Override public void initialize() { try {//from w ww. ja v a 2 s . c o m converter = new VariantContext2VariantConverter(); byte[] variantHeaders = Base64.decodeBase64(getConfiguration().get(VARIANT_HEADER)); VcfBlockIterator iterator = new VcfBlockIterator(new ByteArrayInputStream(variantHeaders), new FullVcfCodec()); header = iterator.getHeader(); int gtSize = header.getGenotypeSamples().size(); variantConverterContext = new VariantConverterContext(); VariantSet vs = new VariantSet(); // vs.setId(file.getName()); // vs.setDatasetId(file.getName()); // vs.setReferenceSetId("test"); vs.setId("test"); //TODO vs.setDatasetId("test"); vs.setReferenceSetId("test"); List<String> genotypeSamples = header.getGenotypeSamples(); Genotype2CallSet gtConverter = new Genotype2CallSet(); for (int gtPos = 0; gtPos < gtSize; ++gtPos) { CallSet cs = gtConverter.forward(genotypeSamples.get(gtPos)); cs.getVariantSetIds().add(vs.getId()); variantConverterContext.getCallSetMap().put(cs.getName(), cs); // callWriter.write(cs); } converter.setContext(variantConverterContext); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:cl.niclabs.tscrypto.common.encryption.KeyChain.java
public byte[] decrypt(String rsaKeyAlias, String encryptedData) { byte[] decrypted = null; try {//from w ww. j a va 2s .c o m Cipher decipher = Cipher.getInstance("RSA"); decipher.init(Cipher.DECRYPT_MODE, getPrivateKey(rsaKeyAlias)); decrypted = decipher.doFinal(Base64.decodeBase64(encryptedData)); } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { e.printStackTrace(); } return decrypted; }
From source file:ar.gob.ambiente.servicios.gestionpersonas.entidades.util.CriptPass.java
/** * Mtodo para desencriptar una contrasea encriptada * @param textoEncriptado//from www . j a v a2 s . c o m * @return * @throws Exception */ public static String desencriptar(String textoEncriptado) throws Exception { String secretKey = "zorbazorbas"; //llave para encriptar datos String base64EncryptedString = ""; try { byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8")); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); byte[] plainText = decipher.doFinal(message); base64EncryptedString = new String(plainText, "UTF-8"); } catch (UnsupportedEncodingException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { System.out.println(ex.getMessage()); } return base64EncryptedString; }
From source file:com.bconomy.autobit.Encryption.java
public static String decrypt(String cyphertext) { if (cyphertext == null || cyphertext.equals("") || !Base64.isBase64(cyphertext)) return ""; try {/*from w w w. java2s . com*/ return new String(decrypt(Base64.decodeBase64(cyphertext)), "UTF-8"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return ""; }
From source file:com.microsoft.azure.batch.auth.BatchCredentialsInterceptor.java
private String sign(String accessKey, String stringToSign) { try {//from www . j ava2 s . c o m // Encoding the Signature // Signature=Base64(HMAC-SHA256(UTF8(StringToSign))) Mac hmac = Mac.getInstance("hmacSHA256"); hmac.init(new SecretKeySpec(Base64.decodeBase64(accessKey), "hmacSHA256")); byte[] digest = hmac.doFinal(stringToSign.getBytes("UTF-8")); return Base64.encodeBase64String(digest); } catch (Exception e) { throw new IllegalArgumentException("accessKey", e); } }
From source file:com.hobba.hobaserver.services.security.TokenUtil.java
public boolean authenticateToken(String token, String kid) { byte[] decodedToken = Base64.decodeBase64(token.getBytes()); String decodedTokenString = new String(decodedToken); String[] fields = decodedTokenString.split(":"); HobaKeysFacadeREST hkfrest = new HobaKeysFacadeREST(); HobaKeys hk = hkfrest.findHKIDbyKID(fields[0]); int userID = hk.getIdDevices().getIduser().getIdUser(); HobaUser hu = hk.getIdDevices().getIduser(); HobaTokenFacadeREST htfrest = new HobaTokenFacadeREST(); HobaToken ht = htfrest.findTokenbyToken(fields[1]); Date date = new Date(); if (ht.getExpiration() != null) { if (date.after(ht.getExpiration())) { return false; }//from ww w .j a v a2s.c om } else { if (!ht.getIsValid()) { return false; } ht.setIsValid(Boolean.FALSE); } HobaUser hu1 = ht.getIdUser(); if (hu.getIdUser() != userID) { return false; } hk = hkfrest.findHKIDbyKID(kid); HobaDevices hd = hk.getIdDevices(); hd.setIduser(hu); HobaDevicesFacadeREST hdfrest = new HobaDevicesFacadeREST(); htfrest.create(ht); hdfrest.create(hd); return true; }
From source file:com.jxt.web.filter.RpcURLPatternFilter.java
public RpcURLPatternFilter(String urlPattern, ServiceTypeRegistryService serviceTypeRegistryService, AnnotationKeyRegistryService annotationKeyRegistryService) { if (urlPattern == null) { throw new NullPointerException("urlPattern must not be null"); }/* ww w . ja v a2 s .c o m*/ // TODO remove decode this.urlPattern = new String(Base64.decodeBase64(urlPattern), UTF8); // TODO serviceType rpctype this.serviceTypeRegistryService = serviceTypeRegistryService; this.annotationKeyRegistryService = annotationKeyRegistryService; this.npcUrl = this.annotationKeyRegistryService.findAnnotationKeyByName("npc.url"); }
From source file:com.cloudera.kitten.util.LocalDataHelper.java
public static <T> Map<String, T> deserialize(String serialized) { byte[] data = Base64.decodeBase64(serialized); ByteArrayInputStream bais = new ByteArrayInputStream(data); Map<String, T> mapping = null; try {//from w w w . ja va 2 s. c o m ObjectInputStream ois = new ObjectInputStream(bais); mapping = (Map<String, T>) ois.readObject(); ois.close(); } catch (Exception e) { throw new RuntimeException(e); } return mapping; }
From source file:com.nestedbird.util.UUIDConverter.java
/** * Converts a Base64 encoded string to a string represented UUID * * @param base64String Base64 Representation of the UUID * @return String represented UUID/*w ww .ja v a 2 s .co m*/ * @throws NullPointerException String must not be null * @throws IllegalArgumentException String should be 22 characters long */ public static String fromBase64(final String base64String) { if (base64String == null) throw new NullPointerException("String cannot be null"); if (base64String.length() != 22) throw new IllegalArgumentException("String should be 22 characters long"); final byte[] bytes = Base64.decodeBase64(base64String); final ByteBuffer bb = ByteBuffer.wrap(bytes); final UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }