List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.mirth.connect.server.util.Pre22PasswordChecker.java
/** * The pre-2.2 password has been migrated to the following * format://w ww. jav a 2 s . c o m * * SALT_ + 8-bit salt + base64(sha(salt + password)) * * To compare: * * 1. Strip the known pre-2.2 prefix * 2. Get the first 8-bits and Base64 decode it, this the salt * 3. Get the remaining bits and Base64 decode it, this is the hash * 4. Pass it into the pre-2.2 password checker algorithm * * @param plainPassword The plain text password to check against the hash * @param encodedPassword The hashed password * @return true if the password matches the hash using the pre-2.2 algorithm, false otherwise */ public static boolean checkPassword(String plainPassword, String encodedPassword) throws Exception { String saltHash = StringUtils.substringAfter(encodedPassword, SALT_PREFIX); String encodedSalt = StringUtils.substring(saltHash, 0, SALT_LENGTH); byte[] decodedSalt = Base64.decodeBase64(encodedSalt); byte[] decodedHash = Base64.decodeBase64(StringUtils.substring(saltHash, encodedSalt.length())); if (Arrays.equals(decodedHash, DigestUtils.sha(ArrayUtils.addAll(decodedSalt, plainPassword.getBytes())))) { return true; } return false; }
From source file:fi.aalto.seqpig.io.BamStorer.java
@Override public void putNext(Tuple f) throws IOException { if (selectedBAMAttributes == null || allBAMFieldNames == null) { try {//from www.ja va 2s . c o m Base64 codec = new Base64(); Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass()); String datastr; datastr = p.getProperty("selectedBAMAttributes"); byte[] buffer = codec.decodeBase64(datastr); ByteArrayInputStream bstream = new ByteArrayInputStream(buffer); ObjectInputStream ostream = new ObjectInputStream(bstream); selectedBAMAttributes = (HashMap<String, Integer>) ostream.readObject(); datastr = p.getProperty("allBAMFieldNames"); buffer = codec.decodeBase64(datastr); bstream = new ByteArrayInputStream(buffer); ostream = new ObjectInputStream(bstream); allBAMFieldNames = (HashMap<String, Integer>) ostream.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } } SAMRecordWritable samrecwrite = new SAMRecordWritable(); SAMRecord samrec = new SAMRecord(samfileheader_decoded); int index = getFieldIndex("name", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setReadName((String) f.get(index)); } index = getFieldIndex("start", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setAlignmentStart(((Integer) f.get(index)).intValue()); } index = getFieldIndex("read", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setReadString((String) f.get(index)); } index = getFieldIndex("cigar", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setCigarString((String) f.get(index)); } index = getFieldIndex("basequal", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setBaseQualityString((String) f.get(index)); } index = getFieldIndex("flags", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setFlags(((Integer) f.get(index)).intValue()); } index = getFieldIndex("insertsize", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setInferredInsertSize(((Integer) f.get(index)).intValue()); } index = getFieldIndex("mapqual", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMappingQuality(((Integer) f.get(index)).intValue()); } index = getFieldIndex("matestart", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMateAlignmentStart(((Integer) f.get(index)).intValue()); } index = getFieldIndex("materefindex", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMateReferenceIndex(((Integer) f.get(index)).intValue()); } index = getFieldIndex("refindex", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setReferenceIndex(((Integer) f.get(index)).intValue()); } index = getFieldIndex("attributes", allBAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.MAP) { Set<Map.Entry<String, Object>> set = ((HashMap<String, Object>) f.get(index)).entrySet(); for (Map.Entry<String, Object> pairs : set) { String attributeName = pairs.getKey(); samrec.setAttribute(attributeName.toUpperCase(), pairs.getValue()); } } samrec.hashCode(); // causes eagerDecode() samrecwrite.set(samrec); try { writer.write(null, samrecwrite); } catch (InterruptedException e) { throw new IOException(e); } }
From source file:controlpac.EncryptHelper.java
public static String Desencriptar(String textoEncriptado) { String base64EncryptedString = ""; try {/*from w ww . j av a 2 s .c o m*/ byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));//Desencodea el texto en base64 MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); //Crea un hash con la clave elegida byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede");//Crea la clave Cipher decipher = Cipher.getInstance("DESede"); decipher.init(Cipher.DECRYPT_MODE, key); //Inicia el descifrado byte[] plainText = decipher.doFinal(message);//Descifra el texto base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { } return base64EncryptedString; }
From source file:fi.aalto.seqpig.io.SamStorer.java
@Override public void putNext(Tuple f) throws IOException { if (selectedSAMAttributes == null || allSAMFieldNames == null) { try {/*from w w w . jav a2 s .c o m*/ Base64 codec = new Base64(); Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass()); String datastr; datastr = p.getProperty("selectedSAMAttributes"); byte[] buffer = codec.decodeBase64(datastr); ByteArrayInputStream bstream = new ByteArrayInputStream(buffer); ObjectInputStream ostream = new ObjectInputStream(bstream); selectedSAMAttributes = (HashMap<String, Integer>) ostream.readObject(); datastr = p.getProperty("allSAMFieldNames"); buffer = codec.decodeBase64(datastr); bstream = new ByteArrayInputStream(buffer); ostream = new ObjectInputStream(bstream); allSAMFieldNames = (HashMap<String, Integer>) ostream.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } } SAMRecordWritable samrecwrite = new SAMRecordWritable(); SAMRecord samrec = new SAMRecord(samfileheader_decoded); int index = getFieldIndex("name", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setReadName((String) f.get(index)); } index = getFieldIndex("start", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setAlignmentStart(((Integer) f.get(index)).intValue()); } index = getFieldIndex("read", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setReadString((String) f.get(index)); } index = getFieldIndex("cigar", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setCigarString((String) f.get(index)); } index = getFieldIndex("basequal", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.CHARARRAY) { samrec.setBaseQualityString((String) f.get(index)); } index = getFieldIndex("flags", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setFlags(((Integer) f.get(index)).intValue()); } index = getFieldIndex("insertsize", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setInferredInsertSize(((Integer) f.get(index)).intValue()); } index = getFieldIndex("mapqual", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMappingQuality(((Integer) f.get(index)).intValue()); } index = getFieldIndex("matestart", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMateAlignmentStart(((Integer) f.get(index)).intValue()); } index = getFieldIndex("materefindex", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setMateReferenceIndex(((Integer) f.get(index)).intValue()); } index = getFieldIndex("refindex", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.INTEGER) { samrec.setReferenceIndex(((Integer) f.get(index)).intValue()); } index = getFieldIndex("attributes", allSAMFieldNames); if (index > -1 && DataType.findType(f.get(index)) == DataType.MAP) { Set<Map.Entry<String, Object>> set = ((HashMap<String, Object>) f.get(index)).entrySet(); for (Map.Entry<String, Object> pairs : set) { String attributeName = pairs.getKey(); samrec.setAttribute(attributeName.toUpperCase(), pairs.getValue()); } } samrec.hashCode(); // causes eagerDecode() samrecwrite.set(samrec); try { writer.write(null, samrecwrite); } catch (InterruptedException e) { throw new IOException(e); } }
From source file:BD.Encriptador.java
public static String Desencriptar(String textoEncriptado) throws Exception { String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {/*ww w .j a v a2s. c o m*/ 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 (Exception ex) { } return base64EncryptedString; }
From source file:com.streamsets.pipeline.stage.processor.statsaggregation.ConfigHelper.java
public static RuleDefinitionsJson readRulesDefinition(String ruleDefinitionsJson, Stage.Context context, List<Stage.ConfigIssue> issues) { RuleDefinitionsJson ruleDefJson = null; if (ruleDefJson != null) { try {//w ww. j a v a 2 s . c om ruleDefJson = ObjectMapperFactory.get() .readValue(new String(Base64.decodeBase64(ruleDefinitionsJson)), RuleDefinitionsJson.class); } catch (IOException ex) { issues.add(context.createConfigIssue(Groups.STATS.getLabel(), "ruleDefinitionsJson", Errors.STATS_01, ex.getMessage(), ex)); } } return ruleDefJson; }
From source file:com.cloud.utils.crypt.RSAHelper.java
private static RSAPublicKey readKey(String key) throws Exception { byte[] encKey = Base64.decodeBase64(key.split(" ")[1]); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(encKey)); byte[] header = readElement(dis); String pubKeyFormat = new String(header); if (!pubKeyFormat.equals("ssh-rsa")) throw new RuntimeException("Unsupported format"); byte[] publicExponent = readElement(dis); byte[] modulus = readElement(dis); KeySpec spec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(publicExponent)); KeyFactory keyFactory = KeyFactory.getInstance("RSA", BouncyCastleProvider.PROVIDER_NAME); RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(spec); return pubKey; }
From source file:com.shareplaylearn.resources.AccessToken.java
/** * TODO: we're abandoning the idea of internal OAUTH flow (it 'twas a teensy shady), and * TODO: this will just be use for users that create their own accounts. * TODO: which means redis, JWT signing & validation utilities, user stores, bcrypt, etc. * @param req//from w ww .j ava 2 s. c o m * @param res * @return */ public static String handlePostAccessToken(Request req, Response res) { String credentialHeader = req.headers("Authorization"); if (credentialHeader == null) { res.body("No credentials provided."); res.status(400); return "Bad Request"; } //TODO: fuzz this to see what happens with bad strings byte[] decodedCredentials = Base64.decodeBase64(credentialHeader.trim()); if (decodedCredentials == null) { res.body("Invalid credentials provided."); res.status(400); return "Bad Request"; } String credentialsString = new String(decodedCredentials, StandardCharsets.UTF_8); String[] credentials = credentialsString.split(":"); if (credentials.length != 3) { res.body("Invalid credentials provided."); res.status(400); return "Bad Request"; } String realm = credentials[0]; String username = credentials[1]; String password = credentials[2]; res.status(500); res.body("Not Implemented."); return "Internal Server Error"; }
From source file:com.opentok.test.Helpers.java
public static boolean verifyTokenSignature(String token, String apiSecret) throws UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { token = token.substring(4);/*from w ww .j a v a 2 s. c o m*/ byte[] buffer = Base64.decodeBase64(token); String decoded = new String(buffer, "UTF-8"); String[] decodedParts = decoded.split(":"); String signature = decodeToken(token).get("sig"); return (signature.equals(signData(decodedParts[1], apiSecret))); }
From source file:lib.clases_cripto.java
public static String Desencriptar(String textoEncriptado) throws Exception { String secretKey = "qualityinfosolutions"; //llave para desenciptar datos String base64EncryptedString = ""; try {//from w w w .j av a 2s. c om 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 (Exception ex) { } return base64EncryptedString; }