List of usage examples for java.util Base64 getEncoder
public static Encoder getEncoder()
From source file:org.codice.alliance.distribution.branding.AllianceBrandingPluginTest.java
@Test public void testProductImage() throws IOException { allianceBrandingPlugin.init();/*from ww w .ja va 2s .c om*/ assertThat(allianceBrandingPlugin.getBase64ProductImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(AllianceBrandingPluginTest.class.getResourceAsStream(productImage)))))); }
From source file:org.codice.ddf.security.idp.binding.post.PostResponseCreator.java
@Override public Response getSamlpResponse(String relayState, AuthnRequest authnRequest, org.opensaml.saml.saml2.core.Response samlResponse, NewCookie cookie) throws WSSecurityException, SimpleSign.SignatureException { LOGGER.debug("Configuring SAML Response for POST."); Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); org.opensaml.saml.saml2.core.Response processingResponse = processPresignPlugins(authnRequest, samlResponse);/*w w w . j a v a 2 s. com*/ LOGGER.debug("Signing SAML POST Response."); getSimpleSign().signSamlObject(processingResponse); LOGGER.debug("Converting SAML Response to DOM"); String assertionResponse = DOM2Writer.nodeToString(OpenSAMLUtil.toDom(processingResponse, doc)); String encodedSamlResponse = Base64.getEncoder() .encodeToString(assertionResponse.getBytes(StandardCharsets.UTF_8)); String assertionConsumerServiceURL = getAssertionConsumerServiceURL(authnRequest); String postForm = createPostResponse(encodedSamlResponse, relayState, assertionConsumerServiceURL); Response.ResponseBuilder ok = Response.ok(postForm); if (cookie != null) { ok = ok.cookie(cookie); } return ok.build(); }
From source file:org.codice.alliance.distribution.branding.TestAllianceBrandingPlugin.java
@Test public void testProductImage() throws IOException { allianceBrandingPlugin.init();//www . j ava 2 s .c o m assertThat(allianceBrandingPlugin.getBase64ProductImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(TestAllianceBrandingPlugin.class.getResourceAsStream(productImage)))))); }
From source file:de.hybris.platform.marketplaceintegration.utils.impl.MarketplaceintegrationHttpUtilImpl.java
private void initConnection(final HttpURLConnection conn) { if (!StringUtils.isEmpty(baseAuthUser) && !StringUtils.isEmpty(baseAuthPassword)) { final String encoding = Base64.getEncoder() .encodeToString(String.format("%s:%s", baseAuthUser, baseAuthPassword).getBytes()); conn.setRequestProperty("Authorization", "Basic " + encoding); }/* w w w .j av a 2 s . c o m*/ for (final Entry<String, String> entry : httpHeaders.entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } }
From source file:org.codice.ddf.branding.impl.DdfBrandingPlugin.java
@Override public String getBase64ProductImage() throws IOException { try (InputStream inputStream = DdfBrandingPlugin.class.getResourceAsStream(getProductImage())) { byte[] productImageAsBytes = IOUtils.toByteArray(inputStream); if (productImageAsBytes.length > 0) { return Base64.getEncoder().encodeToString(productImageAsBytes); }// w w w . j a v a2 s. co m } return ""; }
From source file:org.apache.pulsar.tests.integration.containers.ChaosContainer.java
public void putFile(String path, byte[] contents) throws Exception { String base64contents = Base64.getEncoder().encodeToString(contents); String cmd = String.format("echo %s | base64 -d > %s", base64contents, path); execCmd("bash", "-c", cmd); }
From source file:org.opendaylight.aaa.encrypt.AAAEncryptionServiceImpl.java
public AAAEncryptionServiceImpl(AaaEncryptServiceConfig encrySrvConfig, final DataBroker dataBroker) { SecretKey tempKey = null;/* w ww. ja v a 2 s.c o m*/ IvParameterSpec tempIvSpec = null; if (encrySrvConfig.getEncryptSalt() == null) { throw new IllegalArgumentException( "null encryptSalt in AaaEncryptServiceConfig: " + encrySrvConfig.toString()); } if (encrySrvConfig.getEncryptKey() != null && encrySrvConfig.getEncryptKey().isEmpty()) { LOG.debug("Set the Encryption service password and encrypt salt"); String newPwd = RandomStringUtils.random(encrySrvConfig.getPasswordLength(), true, true); final Random random = new SecureRandom(); byte[] salt = new byte[16]; random.nextBytes(salt); String encodedSalt = Base64.getEncoder().encodeToString(salt); encrySrvConfig = new AaaEncryptServiceConfigBuilder(encrySrvConfig).setEncryptKey(newPwd) .setEncryptSalt(encodedSalt).build(); updateEncrySrvConfig(newPwd, encodedSalt); initializeConfigDataTree(encrySrvConfig, dataBroker); } final byte[] enryptionKeySalt = Base64.getDecoder().decode(encrySrvConfig.getEncryptSalt()); try { final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(encrySrvConfig.getEncryptMethod()); final KeySpec spec = new PBEKeySpec(encrySrvConfig.getEncryptKey().toCharArray(), enryptionKeySalt, encrySrvConfig.getEncryptIterationCount(), encrySrvConfig.getEncryptKeyLength()); tempKey = keyFactory.generateSecret(spec); tempKey = new SecretKeySpec(tempKey.getEncoded(), encrySrvConfig.getEncryptType()); tempIvSpec = new IvParameterSpec(enryptionKeySalt); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { LOG.error("Failed to initialize secret key", e); } key = tempKey; ivspec = tempIvSpec; Cipher cipher = null; try { cipher = Cipher.getInstance(encrySrvConfig.getCipherTransforms()); cipher.init(Cipher.ENCRYPT_MODE, key, ivspec); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { LOG.error("Failed to create encrypt cipher.", e); } this.encryptCipher = cipher; cipher = null; try { cipher = Cipher.getInstance(encrySrvConfig.getCipherTransforms()); cipher.init(Cipher.DECRYPT_MODE, key, ivspec); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { LOG.error("Failed to create decrypt cipher.", e); } this.decryptCipher = cipher; }
From source file:org.codice.ddf.branding.impl.DdfBrandingPluginTest.java
@Test public void testVendorImage() throws IOException { ddfBrandingPlugin.init();//from w ww. j a va 2 s .c o m assertThat(ddfBrandingPlugin.getBase64VendorImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(DdfBrandingPluginTest.class.getResourceAsStream(vendorImage)))))); }
From source file:org.codice.ddf.branding.impl.TestDdfBrandingPlugin.java
@Test public void testVendorImage() throws IOException { ddfBrandingPlugin.init();/* w w w . j a va 2s. c o m*/ assertThat(ddfBrandingPlugin.getBase64VendorImage(), is(equalTo(Base64.getEncoder().encodeToString( IOUtils.toByteArray(TestDdfBrandingPlugin.class.getResourceAsStream(vendorImage)))))); }
From source file:org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor.java
/** * Called every time a HTTP invocation is made. * <p>// ww w . j av a 2 s. c o m * Simply allows the parent to setup the connection, and then adds an * <code>Authorization</code> HTTP header property that will be used for BASIC * authentication. * </p> * <p> * The <code>SecurityContextHolder</code> is used to obtain the relevant principal and * credentials. * </p> * * @param con the HTTP connection to prepare * @param contentLength the length of the content to send * * @throws IOException if thrown by HttpURLConnection methods */ protected void prepareConnection(HttpURLConnection con, int contentLength) throws IOException { super.prepareConnection(con, contentLength); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if ((auth != null) && (auth.getName() != null) && (auth.getCredentials() != null) && !trustResolver.isAnonymous(auth)) { String base64 = auth.getName() + ":" + auth.getCredentials().toString(); con.setRequestProperty("Authorization", "Basic " + new String(Base64.getEncoder().encode(base64.getBytes()))); if (logger.isDebugEnabled()) { logger.debug( "HttpInvocation now presenting via BASIC authentication SecurityContextHolder-derived: " + auth.toString()); } } else { if (logger.isDebugEnabled()) { logger.debug("Unable to set BASIC authentication header as SecurityContext did not provide " + "valid Authentication: " + auth); } } doPrepareConnection(con, contentLength); }