List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.forsrc.utils.MyRsaUtils.java
/** * Decrypt string.//from w w w .j a va2 s . c o m * * @param rsaKey the rsa key * @param encrypted the encrypted * @return the string * @throws IOException the io exception */ public static String decrypt(RsaKey rsaKey, String encrypted) throws IOException { BigInteger encrypt = new BigInteger(new String(new Base64().decode(encrypted))); return bigInteger2String(decrypt(rsaKey, encrypt)); }
From source file:com.networknt.light.util.HashUtil.java
public static String generateUUID() { UUID id = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(id.getMostSignificantBits()); bb.putLong(id.getLeastSignificantBits()); Base64 base64 = new Base64(); return base64.encodeBase64URLSafeString(bb.array()); }
From source file:license.regist.ReadProjectInfo.java
static boolean isRight() { BufferedReader br = null;// w w w .j a va2 s. com try { File f = new File(registerFile()); if (f.isFile()) { FileReader reader = new FileReader(f); br = new BufferedReader(reader); String info = new Blowfish(Date.class.getName()).decryptString(br.readLine()); String md5 = br.readLine(); Base64 base64 = new Base64(); System.out.println(info.length()); byte[] rmd5 = md5(info); byte[] lmd5 = rsa(base64.decode(md5)); System.out.println(base64.encodeToString(rmd5)); System.out.println(base64.encodeToString(lmd5)); if (equalsBytes(rmd5, lmd5)) { Map infoMap = readInfo(info); if (checkPeriod(infoMap)) { if (type.longValue() < 2L) return true; return (checkCpu(infoMap)) && (checkPath(infoMap)) && (checkMac(infoMap)); } } return false; } } catch (Exception e) { return false; } finally { if (br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:com.forsrc.utils.MyDesUtils.java
/** * Decrypt string./*from www. jav a 2 s .co m*/ * * @param des the des * @param code the code * @return String string * @throws DesException the des exception * @Title: decrypt * @Description: */ public static String decrypt(DesKey des, String code) throws DesException { if (des == null) { throw new DesException("DesKey is null."); } if (code == null) { throw new DesException("Decrypted code is null."); } byte[] encrypted = null; try { encrypted = new Base64().decode(code); } catch (Exception e) { throw new DesException(e); } byte[] original = null; try { original = des.getCipher(false).doFinal(encrypted); } catch (IllegalBlockSizeException e) { throw new DesException(e); } catch (BadPaddingException e) { throw new DesException(e); } try { return new String(original, CHARSET_UTF8); } catch (UnsupportedEncodingException e) { throw new DesException(e); } }
From source file:ca.ualberta.physics.cssdp.util.HashUtils.java
/** * From a base 64 representation, returns the corresponding byte[] * /*from w w w . ja v a2 s . c o m*/ * @param data * String The base64 representation * @return byte[] * @throws IOException */ public static byte[] base64ToByte(String data) { Base64 decoder = new Base64(); return decoder.decode(data); }
From source file:com.forsrc.utils.MyAesUtils.java
/** * Decrypt string.// www . jav a 2s. c o m * * @param aes the aes * @param code the code * @return String string * @throws AesException the aes exception * @Title: decrypt * @Description: */ public static String decrypt(AesKey aes, String code) throws AesException { byte[] encrypted = null; try { encrypted = new Base64().decode(code); } catch (Exception e) { throw new AesException(e); } byte[] original = null; try { original = aes.getDecryptCipher().doFinal(encrypted); } catch (IllegalBlockSizeException e) { throw new AesException(e); } catch (BadPaddingException e) { throw new AesException(e); } try { return new String(original, CHARSET_UTF8); } catch (UnsupportedEncodingException e) { throw new AesException(e); } }
From source file:com.cirrus.utils.EncryptionUtils.java
private static String makePasswordHash(final String value, final String salt) { try {//from ww w . jav a 2s.c o m final String saltedAndHashed = value + "," + salt; final MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(saltedAndHashed.getBytes()); final byte hashedBytes[] = (new String(digest.digest(), "UTF-8")).getBytes(); final Base64 base64 = new Base64(); return Arrays.toString(base64.encode(hashedBytes)) + '_' + salt; } catch (final NoSuchAlgorithmException e) { throw new RuntimeException("MD5 is not available", e); } catch (final UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 unavailable? Not a chance", e); } }
From source file:de.extra.client.plugins.outputplugin.crypto.ExtraCryptoUtil.java
/** * Generates a new SecretKeySpec using the encoded string. Uses the * specified algorithm to generate the key. */// w w w . j a va2s . c o m private static SecretKeySpec decodeKey(String encrpKey) throws Exception { SecretKeySpec skeySpec = null; new Base64().decode(encrpKey); byte[] raw = new Base64().decode(encrpKey); skeySpec = new SecretKeySpec(raw, ALGORITHM); return skeySpec; }
From source file:com.forsrc.utils.MyRsa2Utils.java
/** * Decrypt string./*from w ww. j a v a 2s . c om*/ * * @param privateKey the private key * @param cipherText the cipher text * @return the string * @throws RsaException the rsa exception */ public static String decrypt(PrivateKey privateKey, String cipherText) throws RsaException { Cipher cipher = null; try { cipher = Cipher.getInstance(RsaKey.ALGORITHM, new org.bouncycastle.jce.provider.BouncyCastleProvider()); } catch (NoSuchAlgorithmException e) { throw new RsaException(e); } catch (NoSuchPaddingException e) { throw new RsaException(e); } try { cipher.init(Cipher.DECRYPT_MODE, privateKey); } catch (InvalidKeyException e) { throw new RsaException(e); } byte[] input = null; try { input = new Base64().decode(cipherText); } catch (Exception e) { throw new RsaException(e); } ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); try { int blockSize = cipher.getBlockSize(); blockSize = blockSize == 0 ? 117 : blockSize; int i = 0; int start = 0; do { start = i++ * blockSize; baos.write(cipher.doFinal(input, start, blockSize)); } while (input.length - start - blockSize > 0); } catch (IllegalBlockSizeException e) { throw new RsaException(e); } catch (BadPaddingException e) { throw new RsaException(e); } catch (IOException e) { throw new RsaException(e); } return new String(baos.toByteArray()); }
From source file:com.microsoft.applicationinsights.extensibility.initializer.SequencePropertyInitializer.java
private static String uuidToBase64() { Base64 base64 = new Base64(); UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return base64.encodeBase64URLSafeString(bb.array()); }