List of usage examples for org.eclipse.jgit.lib Constants encodeASCII
public static byte[] encodeASCII(String s)
From source file:com.gitblit.transport.ssh.SshKey.java
License:Apache License
public PublicKey getPublicKey() { if (publicKey == null && rawData != null) { // instantiate the public key from the raw key data final String[] parts = rawData.split(" ", 3); if (comment == null && parts.length == 3) { comment = parts[2];//from w ww . jav a 2 s . c o m } final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(parts[1])); try { publicKey = new ByteArrayBuffer(bin).getRawPublicKey(); } catch (SshException e) { throw new RuntimeException(e); } } return publicKey; }
From source file:com.gitblit.transport.ssh.SshKey.java
License:Apache License
public String getFingerprint() { if (fingerprint == null) { StringBuilder sb = new StringBuilder(); // append the key hash as colon-separated pairs String hash;//from w w w .ja v a 2 s . c o m if (rawData != null) { final String[] parts = rawData.split(" ", 3); final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(parts[1])); hash = StringUtils.getMD5(bin); } else { // TODO calculate the correct hash from a PublicKey instance hash = StringUtils.getMD5(getPublicKey().getEncoded()); } for (int i = 0; i < hash.length(); i += 2) { sb.append(hash.charAt(i)).append(hash.charAt(i + 1)).append(':'); } sb.setLength(sb.length() - 1); fingerprint = sb.toString(); } return fingerprint; }
From source file:com.google.gerrit.sshd.SshUtil.java
License:Apache License
/** * Parse a public key into its Java type. * * @param key the account key to parse./*from ww w. j a v a 2 s . co m*/ * @return the valid public key object. * @throws InvalidKeySpecException the key supplied is not a valid SSH key. * @throws NoSuchAlgorithmException the JVM is missing the key algorithm. * @throws NoSuchProviderException the JVM is missing the provider. */ public static PublicKey parse(final AccountSshKey key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException { try { final String s = key.getEncodedKey(); if (s == null) { throw new InvalidKeySpecException("No key string"); } final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(s)); return new Buffer(bin).getRawPublicKey(); } catch (RuntimeException | SshException e) { throw new InvalidKeySpecException("Cannot parse key", e); } }
From source file:com.google.gerrit.sshd.SshUtil.java
License:Apache License
/** * Convert an RFC 4716 style key to an OpenSSH style key. * * @param keyStr the key string to convert. * @return {@code keyStr} if conversion failed; otherwise the converted * key, in OpenSSH key format./* w w w . ja v a2 s . c o m*/ */ public static String toOpenSshPublicKey(final String keyStr) { try { final StringBuilder strBuf = new StringBuilder(); final BufferedReader br = new BufferedReader(new StringReader(keyStr)); String line = br.readLine(); // BEGIN SSH2 line... if (line == null || !line.equals("---- BEGIN SSH2 PUBLIC KEY ----")) { return keyStr; } while ((line = br.readLine()) != null) { if (line.indexOf(':') == -1) { strBuf.append(line); break; } } while ((line = br.readLine()) != null) { if (line.startsWith("---- ")) { break; } strBuf.append(line); } final PublicKey key = new Buffer(Base64.decodeBase64(Constants.encodeASCII(strBuf.toString()))) .getRawPublicKey(); if (key instanceof RSAPublicKey) { strBuf.insert(0, KeyPairProvider.SSH_RSA + " "); } else if (key instanceof DSAPublicKey) { strBuf.insert(0, KeyPairProvider.SSH_DSS + " "); } else { return keyStr; } strBuf.append(' '); strBuf.append("converted-key"); return strBuf.toString(); } catch (IOException e) { return keyStr; } catch (RuntimeException re) { return keyStr; } }
From source file:com.sap.poc.jgit.storage.jdbc.JdbcEnDecoder.java
License:Eclipse Distribution License
static byte[] decodeRowKey(final String sRowKey) { if (sRowKey != null) return Constants.encodeASCII(sRowKey); else/*from w w w. j a v a2s .com*/ return null; }
From source file:com.sonatype.sshjgit.core.NoShell.java
License:Apache License
@Override public Command create() { return new Command() { private InputStream in; private OutputStream out; private OutputStream err; private ExitCallback exit; @Override//from w w w .j a v a 2 s . c om public void setInputStream(InputStream in) { this.in = in; } @Override public void setOutputStream(OutputStream out) { this.out = out; } @Override public void setErrorStream(OutputStream err) { this.err = err; } @Override public void setExitCallback(ExitCallback callback) { this.exit = callback; } @Override public void start(Environment env) throws IOException { err.write(Constants.encodeASCII("sshjgit: no shell available\n")); in.close(); out.close(); err.close(); exit.onExit(127); } @Override public void destroy() { } }; }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkRemoteObjectDatabase.java
License:Eclipse Distribution License
/** * Rebuild the {@link #INFO_PACKS} for dumb transport clients. * <p>/*from w w w. ja va 2 s. c o m*/ * This method rebuilds the contents of the {@link #INFO_PACKS} file to * match the passed list of pack names. * * @param packNames * names of available pack files, in the order they should appear * in the file. Valid pack name strings are of the form * <code>pack-035760ab452d6eebd123add421f253ce7682355a.pack</code>. * @throws IOException * writing is not supported, or attempting to write the file * failed, possibly due to permissions or remote disk full, etc. */ void writeInfoPacks(final Collection<String> packNames) throws IOException { final StringBuilder w = new StringBuilder(); for (final String n : packNames) { w.append("P "); w.append(n); w.append('\n'); } writeFile(INFO_PACKS, Constants.encodeASCII(w.toString())); }