/** * Sign a message and base64 encode the signature. */ public String sign(String msg) { try { RSAPrivateKey key = getPrivateKey(); Signature sig = Signature.getInstance(SIGNING_ALGORITHM + "with" + key.getAlgorithm()); sig.initSign(key); sig.update(msg.getBytes("UTF-8")); return hudson.remoting.Base64.encode(sig.sign()); } catch (GeneralSecurityException e) { throw new SecurityException(e); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); // UTF-8 is mandatory } }
private static HostKey parseKey(String key) throws KeyParseException { if (!key.contains(" ")) { throw new IllegalArgumentException(Messages.ManualKeyProvidedHostKeyVerifier_TwoPartKey()); } StringTokenizer tokenizer = new StringTokenizer(key, " "); String algorithm = tokenizer.nextToken(); byte[] keyValue = Base64.decode(tokenizer.nextToken()); if (null == keyValue) { throw new KeyParseException(Messages.ManualKeyProvidedHostKeyVerifier_Base64EncodedKeyValueRequired()); } return TrileadVersionSupportManager.getTrileadSupport().parseKey(algorithm, keyValue); }
protected static boolean isBase64(char octect) { return (isWhiteSpace(octect) || isPad(octect) || isData(octect)); }
int len = removeWhiteSpace(base64Data); if (!isData( (d1 = base64Data[dataIndex++]) )|| !isData( (d2 = base64Data[dataIndex++]) )|| !isData( (d3 = base64Data[dataIndex++]) )|| !isData( (d4 = base64Data[dataIndex++]) )) return null;//if found "no data" just return null if (!isData( (d1 = base64Data[dataIndex++]) ) || !isData( (d2 = base64Data[dataIndex++]) )) { return null;//if found "no data" just return null if (!isData( (d3 ) ) || !isData( (d4 ) )) {//Check if they are PAD characters if (isPad( d3 ) && isPad( d4)) { //Two PAD e.g. 3c[Pad][Pad] if ((b2 & 0xf) != 0)//last 4 bits should be zero return null; tmp[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ; return tmp; } else if (!isPad( d3) && isPad(d4)) { //One PAD e.g. 3cQ[Pad] b3 = base64Alphabet[ d3 ]; if ((b3 & 0x3 ) != 0)//last 2 bits should be zero
/** * remove WhiteSpace from MIME containing encoded Base64 data. * * @param data the byte array of base64 data (with WS) * @return the new length */ protected static int removeWhiteSpace(char[] data) { if (data == null) return 0; // count characters that's not whitespace int newSize = 0; int len = data.length; for (int i = 0; i < len; i++) { if (!isWhiteSpace(data[i])) data[newSize++] = data[i]; } return newSize; } }
private static HostKey parseKey(String key) throws KeyParseException { if (!key.contains(" ")) { throw new IllegalArgumentException(Messages.ManualKeyProvidedHostKeyVerifier_TwoPartKey()); } StringTokenizer tokenizer = new StringTokenizer(key, " "); String algorithm = tokenizer.nextToken(); byte[] keyValue = Base64.decode(tokenizer.nextToken()); if (null == keyValue) { throw new KeyParseException(Messages.ManualKeyProvidedHostKeyVerifier_Base64EncodedKeyValueRequired()); } return TrileadVersionSupportManager.getTrileadSupport().parseKey(algorithm, keyValue); }
/** * Sign a message and base64 encode the signature. */ public String sign(String msg) { try { RSAPrivateKey key = getPrivateKey(); Signature sig = Signature.getInstance(SIGNING_ALGORITHM + "with" + key.getAlgorithm()); sig.initSign(key); sig.update(msg.getBytes("UTF-8")); return hudson.remoting.Base64.encode(sig.sign()); } catch (GeneralSecurityException e) { throw new SecurityException(e); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); // UTF-8 is mandatory } }
/** * Decodes by the JDK base64 code and make sure the encoded string looks correct. */ private void decodeByMaster(String s, byte[] dataSet) throws IOException { int ptr=0; for( int i=0; i<s.length(); i+=4 ) { byte[] buf = Base64.decode(s.substring(i,i+4)); for (int j = 0; j < buf.length; j++) { if(buf[j]!=dataSet[ptr]) fail("encoding error at offset "+ptr); ptr++; } } }
if (idHeader != null) { try { byte[] encodedKey = Base64.decode(idHeader); if (encodedKey == null) { firstError = chain(firstError, new IOException(
public String getKey() { return key.getAlgorithm() + " " + Base64.encode(key.getKey()); }
public String getKey() { return key.getAlgorithm() + " " + Base64.encode(key.getKey()); }
if (slaveJnlpCredentials != null) { String userPassword = slaveJnlpCredentials; String encoding = Base64.encode(userPassword.getBytes("UTF-8")); http.setRequestProperty("Authorization", "Basic " + encoding); String encoding = Base64.encode(System.getProperty("proxyCredentials", proxyCredentials).getBytes("UTF-8")); http.setRequestProperty("Proxy-Authorization", "Basic " + encoding);
@Override public String getInjectedKey() throws IOException { InstanceIdentity id = InstanceIdentity.get(); return "ssh-rsa " + encode(new RSAKeyAlgorithm().encodePublicKey(id.getPublic())); }
public void testSingleWrite() throws IOException { byte[] ds = getDataSet(65536); String master = Base64.encode(ds); ByteArrayOutputStream buf = new ByteArrayOutputStream(); OutputStream o = BinarySafeStream.wrap(buf); o.write(ds,0,ds.length); o.close(); assertEquals(buf.toString(),master); }
final String encodedScan; try { encodedScan = Base64.encode(artifact.readToString().getBytes(StandardCharsets.UTF_8)); } catch (IOException | InterruptedException e) { logger.log(Messages.Builder_Error_Processing() + ": " + e.getMessage());
public void testChunkedWrites() throws IOException { byte[] ds = getDataSet(65536); String master = Base64.encode(ds); Random r = new Random(0); for( int i=0; i<16; i++) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); OutputStream o = BinarySafeStream.wrap(buf); randomCopy(r,new ByteArrayInputStream(ds),o,false); assertEquals(buf.toString(),master); } }
String content = Util.replaceMacro(userDataText, resolver); LOGGER.fine("Sending user-data:\n" + content); builder.userData(Base64.encode(content.getBytes(Charsets.UTF_8)));