@Override protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException { if (sshKeysByHostname.containsKey(host)) { JGitEnvironmentProperties sshUriProperties = sshKeysByHostname.get(host); jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null); if (sshUriProperties.getKnownHostsFile() != null) { jSch.setKnownHosts(sshUriProperties.getKnownHostsFile()); } if (sshUriProperties.getHostKey() != null) { HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey())); jSch.getHostKeyRepository().add(hostkey, null); } return jSch.getSession(user, host, port); } throw new JSchException("no keys configured for hostname " + host); }
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source) { return encodeBytes(source, 0, source.length); }
b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); b4Posn = 0;
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } return new String(outBuff, 0, e, UTF_8); }
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } return new String(outBuff, 0, e, UTF_8); }
Digest(String hdr) { super(Type.DIGEST); params = parse(hdr); final String qop = params.get("qop"); //$NON-NLS-1$ if ("auth".equals(qop)) { //$NON-NLS-1$ final byte[] bin = new byte[8]; PRNG.nextBytes(bin); params.put("cnonce", Base64.encodeBytes(bin)); //$NON-NLS-1$ } }
public Negotiate(String hdr) { super(Type.NEGOTIATE); prevToken = Base64.decode(hdr); }
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } try { return new String(outBuff, 0, e, UTF_8); } catch (UnsupportedEncodingException uue) { return new String(outBuff, 0, e); } }
b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); b4Posn = 0;
@Override void configureRequest(HttpConnection conn) throws IOException { String ident = user + ":" + pass; //$NON-NLS-1$ String enc = Base64.encodeBytes(ident.getBytes(UTF_8)); conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() + " " + enc); //$NON-NLS-1$ } }
/** * Decodes data from Base64 notation. * * @param s * the string to decode * @return the decoded data */ public static byte[] decode(String s) { byte[] bytes = s.getBytes(UTF_8); return decode(bytes, 0, bytes.length); } }
b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); b4Posn = 0;
final Mac m = Mac.getInstance(HMAC); m.init(privateKey); sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8))); } catch (NoSuchAlgorithmException e) { throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage()));
AlgorithmParameters params = AlgorithmParameters .getInstance(paramsAlgo); params.init(Base64.decode(cont)); decryptCipher.init(Cipher.DECRYPT_MODE, secretKey, params);
@Override OutputStream encrypt(OutputStream output) throws IOException { try { Cipher cipher = InsecureCipherFactory.create(cipherAlgo); cipher.init(Cipher.ENCRYPT_MODE, secretKey); AlgorithmParameters params = cipher.getParameters(); if (params == null) { context = EMPTY; } else { context = Base64.encodeBytes(params.getEncoded()); } return new CipherOutputStream(output, cipher); } catch (Exception e) { throw error(e); } }
public Negotiate(String hdr) { super(Type.NEGOTIATE); prevToken = Base64.decode(hdr); }
final String md5str = Base64.encodeBytes(newMD5().digest(data)); final String lenstr = String.valueOf(data.length); for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) {
public Negotiate(String hdr) { super(Type.NEGOTIATE); prevToken = Base64.decode(hdr); }
@Override void configureRequest(HttpConnection conn) throws IOException { GSSManager gssManager = GSS_MANAGER_FACTORY.newInstance(conn .getURL()); String host = conn.getURL().getHost(); String peerName = "HTTP@" + host.toLowerCase(Locale.ROOT); //$NON-NLS-1$ try { GSSName gssName = gssManager.createName(peerName, GSSName.NT_HOSTBASED_SERVICE); GSSContext context = gssManager.createContext(gssName, OID, null, GSSContext.DEFAULT_LIFETIME); // Respect delegation policy in HTTP/SPNEGO. context.requestCredDeleg(true); byte[] token = context.initSecContext(prevToken, 0, prevToken.length); conn.setRequestProperty(HDR_AUTHORIZATION, getType().getSchemeName() + " " + Base64.encodeBytes(token)); //$NON-NLS-1$ } catch (GSSException e) { throw new IOException(e); } } }
/** * Decodes data from Base64 notation. * * @param s * the string to decode * @return the decoded data */ public static byte[] decode(String s) { byte[] bytes = s.getBytes(UTF_8); return decode(bytes, 0, bytes.length); } }