List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64
public static byte[] encodeBase64(final byte[] binaryData)
From source file:com.microsoft.azure.management.compute.VirtualMachineExtensionOperationsTests.java
@Test public void canEnableDiagnosticsExtension() throws Exception { final String STORAGEACCOUNTNAME = generateRandomResourceName("stg", 15); final String VMNAME = "javavm1"; // Creates a storage account StorageAccount storageAccount = storageManager.storageAccounts().define(STORAGEACCOUNTNAME) .withRegion(REGION).withNewResourceGroup(RG_NAME).create(); // Create a Linux VM ////from w w w . j a va2 s. c o m VirtualMachine vm = computeManager.virtualMachines().define(VMNAME).withRegion(REGION) .withExistingResourceGroup(RG_NAME).withNewPrimaryNetwork("10.0.0.0/28") .withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS) .withRootUsername("Foo12").withRootPassword("BaR@12abc!") .withSize(VirtualMachineSizeTypes.STANDARD_D3).withExistingStorageAccount(storageAccount).create(); final InputStream embeddedJsonConfig = VirtualMachineExtensionOperationsTests.class .getResourceAsStream("/linux_diagnostics_public_config.json"); String jsonConfig = ((new ObjectMapper()).readTree(embeddedJsonConfig)).toString(); jsonConfig = jsonConfig.replace("%VirtualMachineResourceId%", vm.id()); // Update Linux VM to enable Diagnostics vm.update().defineNewExtension("LinuxDiagnostic").withPublisher("Microsoft.OSTCExtensions") .withType("LinuxDiagnostic").withVersion("2.3") .withPublicSetting("ladCfg", new String(Base64.encodeBase64(jsonConfig.getBytes()))) .withPublicSetting("storageAccount", storageAccount.name()) .withProtectedSetting("storageAccountName", storageAccount.name()) .withProtectedSetting("storageAccountKey", storageAccount.getKeys().get(0).value()) .withProtectedSetting("storageAccountEndPoint", "https://core.windows.net:443/").attach().apply(); }
From source file:corner.encrypt.services.impl.CipherKey.java
public void persistCipher() { FileOutputStream fos = null;// w w w . j a va2s. co m try { fos = new FileOutputStream(persisFile); fos.write(Base64.encodeBase64(this.cipher)); fos.flush(); } catch (Throwable e) { System.err.println("Exception during serialization:" + e); } finally { InternalUtils.close(fos); } }
From source file:com.aurel.track.admin.customize.category.filter.execute.ReportQueryBL.java
private static String encrypt(String clearText, char[] password) { // Create PBE parameter set PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count); byte[] ciphertext = { 0 }; PBEKeySpec pbeKeySpec = new PBEKeySpec(password); try {//from w w w. j ava 2 s . c o m SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec); // Create PBE Cipher Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); // Initialize PBE Cipher with key and parameters pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec); // Encrypt the cleartext ciphertext = pbeCipher.doFinal(clearText.getBytes()); } catch (Exception e) { LOGGER.debug(ExceptionUtils.getStackTrace(e), e); } return new String(Base64.encodeBase64(ciphertext)); }
From source file:lti.oauth.OAuthMessageSigner.java
/** * This method double encodes the parameter keys and values. * Thus, it expects the keys and values contained in the 'parameters' SortedMap * NOT to be encoded./*from ww w . ja va 2 s. c o m*/ * * @param secret * @param algorithm * @param method * @param url * @param parameters * @return oauth signature * @throws Exception */ public String sign(String secret, String algorithm, String method, String url, SortedMap<String, String> parameters) throws Exception { SecretKeySpec secretKeySpec = new SecretKeySpec((secret.concat(OAuthUtil.AMPERSAND)).getBytes(), algorithm); Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm()); mac.init(secretKeySpec); StringBuilder signatureBase = new StringBuilder(OAuthUtil.percentEncode(method)); signatureBase.append(OAuthUtil.AMPERSAND); signatureBase.append(OAuthUtil.percentEncode(url)); signatureBase.append(OAuthUtil.AMPERSAND); int count = 0; for (String key : parameters.keySet()) { count++; signatureBase.append(OAuthUtil.percentEncode(OAuthUtil.percentEncode(key))); signatureBase.append(URLEncoder.encode(OAuthUtil.EQUAL, OAuthUtil.ENCODING)); signatureBase.append(OAuthUtil.percentEncode(OAuthUtil.percentEncode(parameters.get(key)))); if (count < parameters.size()) { signatureBase.append(URLEncoder.encode(OAuthUtil.AMPERSAND, OAuthUtil.ENCODING)); } } if (log.isDebugEnabled()) { log.debug(signatureBase.toString()); } byte[] bytes = mac.doFinal(signatureBase.toString().getBytes()); byte[] encodedMacBytes = Base64.encodeBase64(bytes); return new String(encodedMacBytes); }