List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String
public static String encodeBase64String(final byte[] binaryData)
From source file:com.cloudant.tests.AttachmentsTest.java
@Test public void attachmentInline() { Attachment attachment1 = new Attachment("VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=", "text/plain"); Attachment attachment2 = new Attachment(); attachment2.setData(Base64.encodeBase64String("binary string".getBytes())); attachment2.setContentType("text/plain"); Bar bar = new Bar(); // Bar extends Document bar.addAttachment("txt_1.txt", attachment1); bar.addAttachment("txt_2.txt", attachment2); db.save(bar);/*w w w. j av a2 s . co m*/ }
From source file:com.vmware.identity.rest.core.server.test.authorization.token.builder.SAMLTokenBuilderTest.java
public AccessToken build(SamlTokenImpl saml, TokenStyle style, TokenType type, SAMLTokenBuilder builder) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { TokenInfo info = new TokenInfo(style, type, Base64.encodeBase64String(saml.toXml().getBytes())); AccessToken token = builder.build(info); SAMLTokenTestUtil.setValidated(((SAMLToken) token).getSAMLToken()); assertEquals("Subject does not match", PrincipalUtil.createUPN(saml.getSubject()), token.getSubject()); assertEquals("Issuer does not match", saml.getIssuerNameId().getValue(), token.getIssuer()); assertEquals("Issued At does not match", saml.getStartTime(), token.getIssueTime()); assertEquals("Expiration Time does not match", saml.getExpirationTime(), token.getExpirationTime()); assertCollectionEquals("Audience is not contained in the token", saml.getAudience(), token.getAudience()); return token; }
From source file:be.fedict.eid.pkira.contracts.EIDPKIRAContractsClient.java
/** * Marshals the document to a base64 string containing XML. * /*from w w w .j av a 2 s . com*/ * @param contractDocument * document to marshal. * @return the base64 data. * @throws XmlMarshallingException * when this fails. */ public <T extends EIDPKIRAContractType> String marshalToBase64(T contractDocument, Class<T> clazz) throws XmlMarshallingException { try { String xml = marshal(contractDocument, clazz); byte[] bytes = xml.getBytes(ENCODING); return Base64.encodeBase64String(bytes); } catch (UnsupportedEncodingException e) { throw new XmlMarshallingException("Error encoding base64 data.", e); } }
From source file:com.github.aynu.yukar.framework.util.SecurityHelper.java
/** * RSA???//from w ww . jav a2 s. c o m * <dl> * <dt>? * <dd>RSA??????2048?????? * </dl> * @return RSA? */ public static KeyPair createKeyPair() { try { final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(2048); final KeyPair pair = generator.generateKeyPair(); if (LOG.isDebugEnabled()) { final RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); final RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate(); LOG.debug("public-modulus={}", Base64.encodeBase64String(publicKey.getModulus().toByteArray())); LOG.debug("public-exponent={}", Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray())); LOG.debug("private-modulus={}", Base64.encodeBase64String(privateKey.getModulus().toByteArray())); LOG.debug("private-exponent={}", Base64.encodeBase64String(privateKey.getPrivateExponent().toByteArray())); } return pair; } catch (final NoSuchAlgorithmException e) { throw new StandardRuntimeException(e); } }
From source file:com.thoughtworks.go.agent.common.util.HeaderUtilTest.java
private void assertExtraProperties(String actualHeaderValueBeforeBase64, Map<String, String> expectedProperties) { String headerValueInBase64 = Base64.encodeBase64String(actualHeaderValueBeforeBase64.getBytes(UTF_8)); assertExtraPropertiesWithoutBase64(headerValueInBase64, expectedProperties); }
From source file:httpget.HttpGet.java
public HttpGet(String url_str, String uName, String uPass) throws HttpGetException { Map<String, String> authHeader = new HashMap<String, String>(); authHeader.put("Authorization", "Basic " + Base64.encodeBase64String(new String(uName + ":" + uPass).getBytes()).trim()); this.init(url_str, 30, authHeader); }
From source file:com.cloudbees.plugins.credentials.SecretBytesTest.java
@Test public void encryptedValuePattern() { Random entropy = new Random(); for (int i = 1; i < 100; i++) { String plaintext = Base64.encodeBase64String(RandomStringUtils.random(entropy.nextInt(i)).getBytes()); SecretBytes secretBytes = SecretBytes.fromString(plaintext); String ciphertext = secretBytes.toString(); // System.out.printf("%s%n %s%n %s%n", plaintext, ciphertext, secretBytes); assertThat(SecretBytes.ENCRYPTED_VALUE_PATTERN.matcher(ciphertext).matches(), is(true)); }/*from ww w. j a va 2 s .co m*/ }
From source file:bftsmart.tom.util.RSAKeyPairGenerator.java
private String getKeyAsString(Key key) { byte[] keyBytes = key.getEncoded(); return Base64.encodeBase64String(keyBytes); }
From source file:com.consol.citrus.functions.core.DigestAuthHeaderFunction.java
/** * {@inheritDoc}/*w ww. j a v a 2 s .com*/ */ public String execute(List<String> parameterList, TestContext context) { if (parameterList == null || parameterList.size() < 8) { throw new InvalidFunctionUsageException( "Function parameters not set correctly - need parameters: username,password,realm,noncekey,method,uri,opaque,algorithm"); } StringBuilder authorizationHeader = new StringBuilder(); String username = parameterList.get(0); String password = parameterList.get(1); String realm = parameterList.get(2); String noncekey = parameterList.get(3); String method = parameterList.get(4); String uri = parameterList.get(5); String opaque = parameterList.get(6); String algorithm = parameterList.get(7); String digest1 = username + ":" + realm + ":" + password; String digest2 = method + ":" + uri; Long expirationTime = System.currentTimeMillis() + nonceValidity; String nonce = Base64.encodeBase64String( (expirationTime + ":" + getDigestHex(algorithm, expirationTime + ":" + noncekey)).getBytes()); authorizationHeader.append("Digest username="); authorizationHeader.append(username); authorizationHeader.append(",realm="); authorizationHeader.append(realm); authorizationHeader.append(",nonce="); authorizationHeader.append(nonce); authorizationHeader.append(",uri="); authorizationHeader.append(uri); authorizationHeader.append(",response="); authorizationHeader.append(getDigestHex(algorithm, getDigestHex(algorithm, digest1) + ":" + nonce + ":" + getDigestHex(algorithm, digest2))); authorizationHeader.append(",opaque="); authorizationHeader.append(getDigestHex(algorithm, opaque)); authorizationHeader.append(",algorithm="); authorizationHeader.append(algorithm); return authorizationHeader.toString(); }
From source file:com.netflix.spinnaker.echo.config.JiraConfig.java
@Bean JiraService jiraService(JiraProperties jiraProperties, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) { if (x509ConfiguredClient != null) { LOGGER.info("Using X509 Cert for Jira Client"); retrofitClient = x509ConfiguredClient; }/*www. ja v a 2 s . c o m*/ RestAdapter.Builder builder = new RestAdapter.Builder() .setEndpoint(newFixedEndpoint(jiraProperties.getBaseUrl())).setClient(retrofitClient) .setLogLevel(retrofitLogLevel).setLog(new Slf4jRetrofitLogger(JiraService.class)); if (x509ConfiguredClient == null) { String credentials = String.format("%s:%s", jiraProperties.getUsername(), jiraProperties.getPassword()); final String basic = String.format("Basic %s", Base64.encodeBase64String(credentials.getBytes())); builder.setRequestInterceptor(request -> { request.addHeader("Authorization", basic); request.addHeader("Accept", "application/json"); }); } return builder.build().create(JiraService.class); }