List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64
public static byte[] decodeBase64(final byte[] base64Data)
From source file:com.vmware.o11n.plugin.crypto.CryptoEncryptionServiceTest.java
@Test public void aesTestStaticAES128() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String ivB64 = service.generateRandomBytes(16); String dataB64 = encodingService.base64Encode(staticString); String secretB64 = digestService.md5Base64(encodingService.base64Encode(staticSecret)); byte[] secretBytes = Base64.decodeBase64(secretB64); assertEquals("secretLength", 16, secretBytes.length); String encryptedB64 = service.aesEncrypt(dataB64, secretB64, ivB64); String decryptedB64 = service.aesDecrypt(encryptedB64, secretB64, ivB64); String decrypted = encodingService.base64Decode(decryptedB64); assertEquals("AES", staticString, decrypted); }
From source file:de.tntinteractive.portalsammler.engine.CryptoHelper.java
public static byte[] keyFromString(final String pw) { return Base64.decodeBase64(pw); }
From source file:net.sf.hajdbc.codec.crypto.CipherCodecFactoryTest.java
@Before public void before() throws Exception { File file = File.createTempFile("ha-jdbc", "keystore"); SecretKeyFactory factory = SecretKeyFactory.getInstance(ALGORITHM); this.key = factory.generateSecret(new DESKeySpec(Base64.decodeBase64(KEY.getBytes()))); KeyStore store = KeyStore.getInstance(CipherCodecFactory.Property.KEYSTORE_TYPE.defaultValue); store.load(null, null);/*w ww .j a v a 2 s. co m*/ store.setKeyEntry(CipherCodecFactory.Property.KEY_ALIAS.defaultValue, this.key, KEY_PASSWORD.toCharArray(), null); FileOutputStream out = new FileOutputStream(file); try { store.store(out, STORE_PASSWORD.toCharArray()); } finally { Resources.close(out); } System.setProperty(CipherCodecFactory.Property.KEYSTORE_FILE.name, file.getPath()); System.setProperty(CipherCodecFactory.Property.KEYSTORE_PASSWORD.name, STORE_PASSWORD); System.setProperty(CipherCodecFactory.Property.KEY_PASSWORD.name, KEY_PASSWORD); }
From source file:me.brjannc.plugins.sushi.AuthorizedKeysDecoder.java
public PublicKey decodePublicKey(String keyLine) throws Exception { bytes = null;//from ww w . ja va 2 s. c o m pos = 0; // look for the Base64 encoded part of the line to decode // both ssh-rsa and ssh-dss begin with "AAAA" due to the length bytes for (String part : keyLine.split(" ")) { if (part.startsWith("AAAA")) { bytes = Base64.decodeBase64(part); break; } } if (bytes == null) { throw new IllegalArgumentException("no Base64 part to decode"); } String type = decodeType(); if (type.equals("ssh-rsa")) { BigInteger e = decodeBigInt(); BigInteger m = decodeBigInt(); RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e); return KeyFactory.getInstance("RSA").generatePublic(spec); } else if (type.equals("ssh-dss")) { BigInteger p = decodeBigInt(); BigInteger q = decodeBigInt(); BigInteger g = decodeBigInt(); BigInteger y = decodeBigInt(); DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g); return KeyFactory.getInstance("DSA").generatePublic(spec); } else { throw new IllegalArgumentException("unknown type " + type); } }
From source file:com.qmetry.qaf.automation.util.FileUtil.java
public static String saveImageFile(String base64Str, String prefix, String dir) throws Exception { byte[] decodedScreenshot = Base64.decodeBase64(base64Str.getBytes());// new File file = generateFile(prefix, ".png", dir); FileOutputStream fos = new FileOutputStream(file); fos.write(decodedScreenshot);/*from ww w. j a v a 2s . c o m*/ fos.close(); return file.getName(); }
From source file:com.fortmoon.utils.SymmetricCypher.java
public String decypher(String cipher) { try {/*from w ww . j av a2 s . c om*/ Cipher jceCipher = Cipher.getInstance(cipherTransformation); jceCipher.init(2, secretKeySpec); byte ciphertext[] = cipher.getBytes(); byte decodedText[] = Base64.decodeBase64(ciphertext); byte cleartext[] = jceCipher.doFinal(decodedText); String res = new String(cleartext); return res; } catch (GeneralSecurityException gse) { throw new EncryptionRuntimeException((new StringBuilder("Failed to decrypt: ")).append(cipher) .append(" exception: ").append(gse.getMessage()).toString(), gse); } }
From source file:com.hadoopvietnam.commons.crypt.J2MECrypto.java
public byte[] decrypt(byte[] crypt) { crypt = Base64.decodeBase64(new String(crypt)); int[] buffer = new int[crypt.length / 4]; pack(crypt, buffer, 0);/*from w w w .j a v a 2 s .c o m*/ unbrew(buffer); return unpack(buffer, 1, buffer[0]); }
From source file:io.hawkcd.agent.services.SecurityService.java
public String decrypt(String encrypted) { try {/*from www. j a v a2 s . c om*/ byte[] decodedValue = Base64.decodeBase64(getBytes(encrypted)); Cipher cipher = getCipher(Cipher.DECRYPT_MODE); byte[] decryptedValue = cipher.doFinal(decodedValue); String result = new String(decryptedValue); return result; } catch (Throwable t) { throw new RuntimeException(t); } }
From source file:de.taimos.dvalin.interconnect.model.MessageCryptoUtil.java
/** * * @param data the BASE 64 data/*from ww w. j a va2 s. com*/ * @return the decrypted data * @throws CryptoException on decryption error */ public static String decrypt(final String data) throws CryptoException { if (data == null) { return null; } try { final Cipher cipher = MessageCryptoUtil.getCipher(Cipher.DECRYPT_MODE); return new String(cipher.doFinal(Base64.decodeBase64(data)), Charset.forName("UTF-8")); } catch (final Exception e) { throw new CryptoException("Decryption of data failed!", e); } }
From source file:com.temenos.useragent.generic.context.BaseConnectionConfig.java
private Properties getBaseConnectionProperties() { Properties baseConnprops = new Properties(); baseConnprops.setProperty(ConnectionConfig.ENDPOINT_URI, "http://localhost:9089/t24interactiontests-iris/t24interactiontests.svc"); baseConnprops.setProperty(ConnectionConfig.SERVICE_ROOT, "GB0010001"); baseConnprops.setProperty(ConnectionConfig.USER_NAME, "INPUTT"); baseConnprops.setProperty(ConnectionConfig.PASS_WORD, Base64.decodeBase64("MTIzNDU2").toString()); return baseConnprops; }