List of usage examples for org.bouncycastle.util.encoders Base64 encode
public static byte[] encode(byte[] data)
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
private Response triggerPipelineUsingAPI(String name) { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }/* w w w .j ava 2 s.com*/ headers.put("Accept", triggerPipelineAPIVersion); headers.put("Content-Type", "application/json"); headers.put("X-GoCD-Confirm", "true"); return RestAssured.given().headers(headers).when().post( Urls.urlFor(String.format("/go/api/pipelines/%s/schedule", scenarioState.pipelineNamed(name)))); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
@com.thoughtworks.gauge.Step("Pause pipeline with reason <pauseCause>") public void pausePipelineWithReason(String pauseCause) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }//from ww w. j a v a2 s .c o m headers.put("Accept", pausePipelineAPIVersion); headers.put("Content-Type", "application/json"); RestAssured.given().headers(headers).body(String.format("{\"pause_cause\": \"%s\"}", pauseCause)).when() .post(Urls.urlFor( String.format("/go/api/pipelines/%s/pause", scenarioState.currentRuntimePipelineName()))) .then().statusCode(200); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
private Response getPipelineStatus(String name) { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }//from w w w .j a va 2s .c om return RestAssured.given().headers(headers).when() .get(Urls.urlFor(String.format("/go/api/pipelines/%s/status", name))); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
@com.thoughtworks.gauge.Step("Unpause pipeline") public void unpausePipeline() throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }/* w w w. j av a2s . com*/ headers.put("Accept", pausePipelineAPIVersion); headers.put("X-GoCD-Confirm", "true"); RestAssured.given().headers(headers).when() .post(Urls.urlFor( String.format("/go/api/pipelines/%s/unpause", scenarioState.currentRuntimePipelineName()))) .then().statusCode(200); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
@com.thoughtworks.gauge.Step("Open changes section for counter <counter>") public void openChangesSectionForCounter(final int counter) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }/*w w w. j a va 2 s . co m*/ headers.put("Accept", buildCauseAPIVersion); headers.put("X-GoCD-Confirm", "true"); Response response = RestAssured.given().headers(headers).when() .get(Urls.urlFor(String.format("/go/api/internal/build_cause/%s/%s", scenarioState.currentRuntimePipelineName(), counter))); scenarioState.storeBuildCauseResponse(response); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
private void cancelStageOfThePipelineWithLabel(int oneBasedStageIndex, String pipelineLabel, int pipelineCounter) throws Exception { String stageName = stageName(pipelineLabel, oneBasedStageIndex); HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }/*from w w w . j av a 2s.c om*/ headers.put("Confirm", "true"); RestAssured.given().headers(headers).when().post(Urls.urlFor(String.format("/go/api/stages/%s/%s/cancel", scenarioState.currentRuntimePipelineName(), stageName))).then().statusCode(200); }
From source file:com.tremolosecurity.proxy.myvd.inserts.admin.PBKDF2.java
License:Apache License
public static String generateHash(String password) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { StringBuffer b = new StringBuffer(); b.append("{myvd}"); //generate salt SecureRandom sr = new SecureRandom(); byte[] salt = new byte[16]; sr.nextBytes(salt);/* w ww . j a v a2 s. c o m*/ b.append(new String(Base64.encode(salt))).append(':'); byte[] hashed = deriveKey(password.getBytes("UTF-8"), salt, 10000, 32); b.append(new String(Base64.encode(hashed))); return b.toString(); }
From source file:com.vmware.admiral.common.util.KeyUtil.java
License:Open Source License
public static String toPublicOpenSSHFormat(RSAPublicKey rsaPublicKey) { ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(byteOs); try {//from w w w . ja v a2 s . c o m dos.writeInt("ssh-rsa".getBytes().length); dos.write("ssh-rsa".getBytes()); dos.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length); dos.write(rsaPublicKey.getPublicExponent().toByteArray()); dos.writeInt(rsaPublicKey.getModulus().toByteArray().length); dos.write(rsaPublicKey.getModulus().toByteArray()); String publicKeyEncoded = new String(Base64.encode(byteOs.toByteArray())); return "ssh-rsa " + publicKeyEncoded; } catch (IOException e) { throw new RuntimeException("Failed to encode public key to OpenSSH format", e); } }
From source file:com.zotoh.crypto.Crypto.java
License:Open Source License
private byte[] fmtPEM(String top, String end, byte[] bits) throws IOException { ByteOStream baos = new ByteOStream(); byte[] bb = new byte[1]; int pos = 0;//from w ww. j av a2 s .c om baos.write(asBytes(top)); bits = Base64.encode(bits); for (int i = 0; i < bits.length; ++i) { if (pos > 0 && (pos % 64) == 0) { baos.write(asBytes("\n")); } ++pos; bb[0] = bits[i]; baos.write(bb); } baos.write(asBytes(end)); return baos.asBytes(); }
From source file:crossbear.CertificateManager.java
License:Open Source License
/** * Get the PEM-representation of a certificate. * /*from w ww.ja v a 2s . co m*/ * Please note: The PEM encoding returned by this function is structured in lines of 64 characters each. Linebreaks are equal to a \n * * @param cert * The certificate * @return The PEM representation of cert * @throws CertificateEncodingException */ private static String getPemEncoding(X509Certificate cert) throws CertificateEncodingException { // Get the bytes of the certificate(DER) and encode them in base64 String base64EncodedCert = new String(Base64.encode(cert.getEncoded())); // Write the PEM header String re = "-----BEGIN CERTIFICATE-----\n"; // Write the certificate data in lines of 64 chars int len = base64EncodedCert.length(); for (int i = 0; i < len; i += 64) { re += base64EncodedCert.substring(i, Math.min(len, i + 64)) + "\n"; } // Write the PEM trailer re += "-----END CERTIFICATE-----"; // Return the PEM-representation of the certificate return re; }