com.trilead.ssh2.crypto.Base64.encode()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中com.trilead.ssh2.crypto.Base64.encode()方法的一些代码示例,展示了Base64.encode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encode()方法的具体详情如下:
包路径:com.trilead.ssh2.crypto.Base64
类名称:Base64
方法名:encode

Base64.encode介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

public static String scramble(String secret) {
  if(secret==null)    return null;
  try {
    return new String(Base64.encode(secret.getBytes("UTF-8")));
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Utility method supporting both possible digest formats: Base64 and Hex
 */
private boolean digestMatches(byte[] digest, String providedDigest) {
  return providedDigest.equalsIgnoreCase(Hex.encodeHexString(digest)) || providedDigest.equalsIgnoreCase(new String(Base64.encode(digest)));
}

代码示例来源:origin: jenkinsci/jenkins

public static String protect(String secret) {
  try {
    Cipher cipher = Secret.getCipher(ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, DES_KEY);
    return new String(Base64.encode(cipher.doFinal((secret+ MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: jenkinsci/jenkins

pos+=iv.length;
  System.arraycopy(encrypted, 0, payload, pos, encrypted.length);
  return "{"+new String(Base64.encode(payload))+"}";
} catch (GeneralSecurityException e) {
  throw new Error(e); // impossible

代码示例来源:origin: jenkinsci/jenkins

public long writeHtmlTo(long start, Writer w) throws IOException {
  ConsoleAnnotationOutputStream<T> caw = new ConsoleAnnotationOutputStream<>(
      w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
  long r = super.writeLogTo(start,caw);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  Cipher sym = PASSING_ANNOTATOR.encrypt();
  ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
  oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
  oos.writeObject(caw.getConsoleAnnotator());
  oos.close();
  StaplerResponse rsp = Stapler.getCurrentResponse();
  if (rsp!=null)
    rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
  return r;
}

代码示例来源:origin: jenkinsci/jenkins

return new String(Base64.encode(baos.toByteArray()));
} catch (GeneralSecurityException e) {
  throw new Error(e); // impossible

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public static String scramble(String secret) {
  if(secret==null)    return null;
  try {
    return new String(Base64.encode(secret.getBytes("UTF-8")));
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public static String scramble(String secret) {
  if(secret==null)    return null;
  try {
    return new String(Base64.encode(secret.getBytes("UTF-8")));
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: hudson/hudson-2.x

public static String scramble(String secret) {
  if(secret==null)    return null;
  try {
    return new String(Base64.encode(secret.getBytes("UTF-8")));
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: hudson/hudson-2.x

public static String protect(String secret) {
  try {
    Cipher cipher = Secret.getCipher(ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, DES_KEY);
    return new String(Base64.encode(cipher.doFinal((secret+ MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public static String protect(String secret) {
  try {
    Cipher cipher = Secret.getCipher(ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, DES_KEY);
    return new String(Base64.encode(cipher.doFinal((secret+ MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public static String protect(String secret) {
  try {
    Cipher cipher = Secret.getCipher(ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, DES_KEY);
    return new String(Base64.encode(cipher.doFinal((secret+ MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: org.kohsuke/trilead-putty-extension

/**
 * Converts that to base64 with new lines to make it 64-chars per line.
 */
public String toBase64() {
  char[] r = Base64.encode(toByteArray());
  StringBuilder buf = new StringBuilder();
  for (int i=0; i<r.length; i++) {
    buf.append(r[i]);
    if (i%64 == 63)
      buf.append('\n');
  }
  if (r.length%64 != 0)
    buf.append('\n');
  return buf.toString();
}

代码示例来源:origin: org.hudsonci.plugins/subversion

public SslClientCertificateCredential(File certificate, String password) throws IOException {
  this.password = Scrambler.scramble(password);
  this.certificate = Secret.fromString(
    new String(Base64.encode(FileUtils.readFileToByteArray(certificate))));
}

代码示例来源:origin: org.jvnet.hudson.plugins/subversion

public SslClientCertificateCredential(File certificate, String password) throws IOException {
  this.password = Scrambler.scramble(password);
  this.certificate = Secret.fromString(
    new String(Base64.encode(FileUtils.readFileToByteArray(certificate))));
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Encrypts {@link #value} and returns it in an encoded printable form.
 *
 * @see #toString() 
 */
public String getEncryptedValue() {
  try {
    Cipher cipher = getCipher("AES");
    cipher.init(Cipher.ENCRYPT_MODE, getKey());
    // add the magic suffix which works like a check sum.
    return new String(Base64.encode(cipher.doFinal((value+MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Encrypts {@link #value} and returns it in an encoded printable form.
 *
 * @see #toString() 
 */
public String getEncryptedValue() {
  try {
    Cipher cipher = getCipher("AES");
    cipher.init(Cipher.ENCRYPT_MODE, getKey());
    // add the magic suffix which works like a check sum.
    return new String(Base64.encode(cipher.doFinal((value+MAGIC).getBytes("UTF-8"))));
  } catch (GeneralSecurityException e) {
    throw new Error(e); // impossible
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  }
}

代码示例来源:origin: jenkinsci/trilead-ssh2

/**
 * Generate the hashed representation of the given hostname. Useful for adding entries
 * with hashed hostnames to a known_hosts file. (see -H option of OpenSSH key-gen).
 *  
 * @param hostname the hostname to hash
 * @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
 */
public static String createHashedHostname(String hostname)
{
  SHA1 sha1 = new SHA1();
  byte[] salt = new byte[sha1.getDigestLength()];
  SECURE_RANDOM.nextBytes(salt);
  byte[] hash = hmacSha1Hash(salt, hostname);
  String base64_salt = new String(Base64.encode(salt));
  String base64_hash = new String(Base64.encode(hash));
  return "|1|" + base64_salt + "|" + base64_hash;
}

代码示例来源:origin: jenkinsci/subversion-plugin

public SslClientCertificateCredential(File certificate, String password) throws IOException {
  this.password = Secret.fromString(Scrambler.scramble(password));
  this.certificate = Secret.fromString(new String(Base64.encode(FileUtils.readFileToByteArray(certificate))));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public long writeHtmlTo(long start, Writer w) throws IOException {
  ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(
      w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
  long r = super.writeLogTo(start,caw);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  Cipher sym = PASSING_ANNOTATOR.encrypt();
  ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
  oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
  oos.writeObject(caw.getConsoleAnnotator());
  oos.close();
  StaplerResponse rsp = Stapler.getCurrentResponse();
  if (rsp!=null)
    rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
  return r;
}

相关文章