List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64(final int lineLength)
From source file:au.com.borner.salesforce.client.rest.domain.LoginResponse.java
public void verify(String consumerSecret) { SecretKey hmacKey = null;/*www .j a v a 2 s . c o m*/ try { byte[] key = consumerSecret.getBytes(); hmacKey = new SecretKeySpec(key, ALGORITHM); Mac mac = Mac.getInstance(ALGORITHM); mac.init(hmacKey); byte[] digest = mac.doFinal((getIdUrl() + getIssuedAt()).getBytes()); byte[] decode_sig = new Base64(true).decode(getSignature()); if (!Arrays.equals(digest, decode_sig)) { throw new SecurityException("Signature could not be verified!"); } } catch (NoSuchAlgorithmException e) { throw new SecurityException(String.format( "Algorithm not found while trying to verifying signature: algorithm=%s; message=%s", ALGORITHM, e.getMessage()), e); } catch (InvalidKeyException e) { throw new SecurityException( String.format("Invalid key encountered while trying to verify signature: key=%s; message=%s", hmacKey, e.getMessage()), e); } }
From source file:at.asitplus.regkassen.core.base.util.CashBoxUtils.java
/** * BASE64 encoding helper function/*from w w w .ja va 2 s. c o m*/ * * @param data binary representation of data to be encoded * @param isUrlSafe indicates whether BASE64 URL-safe encoding should be used (required for JWS) * @return BASE64 encoded representation of input data */ public static String base64Encode(byte[] data, boolean isUrlSafe) { Base64 encoder = new Base64(isUrlSafe); return new String(encoder.encode(data)).replace("\r\n", ""); }
From source file:fr.amapj.service.engine.sudo.SudoManager.java
private String generateSudo() { try {//from ww w . ja v a2 s . c o m SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; random.nextBytes(salt); Base64 coder = new Base64(true); String str = coder.encodeAsString(salt); str = str.replace('\r', '0'); str = str.replace('\n', '0'); return str; } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Erreur inattendue", e); } }
From source file:MailServlet.java
public static String base64UrlDecode(String input) { String result = null;//from w w w. j av a2s.com Base64 decoder = new Base64(true); byte[] decodedBytes = decoder.decode(input); result = new String(decodedBytes); return result; }
From source file:at.asitplus.regkassen.core.base.util.CashBoxUtils.java
/** * BASE64 decoder helper function/*ww w. j av a 2s . c o m*/ * * @param base64Data BASE64 encoded data * @param isUrlSafe indicates whether BASE64 URL-safe encoding was used (required for JWS) * @return binary representation of decoded data */ public static byte[] base64Decode(String base64Data, boolean isUrlSafe) { Base64 decoder = new Base64(isUrlSafe); return decoder.decode(base64Data); }
From source file:ch.boye.httpclientandroidlib.impl.auth.BasicScheme.java
/** * @since 4.3// w ww.jav a2 s . c o m */ public BasicScheme(final Charset credentialsCharset) { super(credentialsCharset); this.base64codec = new Base64(0); this.complete = false; }
From source file:com.netcrest.pado.internal.security.AESCipher.java
public static String encryptUserTextToText(String clearText) throws Exception { if (clearText == null) { return null; }//from w w w . ja va 2 s . co m byte[] encrypted = AESCipher.encryptUserTextToBinary(clearText); Base64 base64 = new Base64(0); // no line breaks return base64.encodeAsString(encrypted); }
From source file:com.leclercb.commons.api.license.LicenseManager.java
public static String keyEncoder(InputStream publicKey) throws Exception { byte[] input = IOUtils.toByteArray(publicKey); Base64 base64 = new Base64(40); byte[] data = base64.encode(input); return new String(data, "UTF-8"); }
From source file:com.leclercb.commons.api.license.LicenseManager.java
public License readLicense(String input) throws Exception { input = input.trim();/*ww w. ja v a2 s.com*/ Base64 base64 = new Base64(40); byte[] data = base64.decode(input); byte[] signature = ArrayUtils.subarray(data, 0, BIT_LENGTH / 8); byte[] message = ArrayUtils.subarray(data, BIT_LENGTH / 8, data.length); if (!this.encryptionManager.verify(message, signature)) { return null; } return License.parseLicense(new String(message, "UTF-8")); }
From source file:com.vmware.bdd.security.EncryptionGuard.java
/** * Decrypt the encrypted text against given secret key. * //from w w w . j av a2 s. c o m * @param encodedText * the encrypted string * @return the clear string, or null if encrypted string is null * @throws CommonException * if input arguments is null */ public static String decode(String encodedText) throws GeneralSecurityException, UnsupportedEncodingException { if (encodedText == null) { return null; } if (encodedText.length() < SALT_SIZE) { throw EncryptionException.SHORT_ENCRYPTED_STRING(encodedText); } Key key = GuardKeyStore.getEncryptionKey(); String salt = encodedText.substring(0, SALT_SIZE); String encryptedText = encodedText.substring(SALT_SIZE); Base64 base64 = new Base64(0); // 0 - no chunking byte[] encryptedBytes = base64.decode(encryptedText); Cipher cipher = getCiperInternal(Cipher.DECRYPT_MODE, key); byte[] outputBytes = cipher.doFinal(encryptedBytes); String outputText = new String(outputBytes, UTF8_ENCODING); AuAssert.check(salt.equals(outputText.substring(0, SALT_SIZE))); // Assert salt return outputText.substring(SALT_SIZE); }