com.trilead.ssh2.crypto.Base64类的使用及代码示例

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

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

Base64介绍

[英]Basic Base64 Support.
[中]基本的Base64支持。

代码示例

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

public static String descramble(String scrambled) {
    if(scrambled==null)    return null;
    try {
      return new String(Base64.decode(scrambled.toCharArray()),"UTF-8");
    } catch (IOException e) {
      return "";  // corrupted data.
    }
  }
}

代码示例来源: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: 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: jenkinsci/subversion-plugin

@Override
public SVNAuthentication createSVNAuthentication(String kind) {
  if(kind.equals(ISVNAuthenticationManager.SSL))
    try {
      SVNSSLAuthentication authentication = SVNSSLAuthentication.newInstance(
          Base64.decode(certificate.getPlainText().toCharArray()),
          Scrambler.descramble(Secret.toString(password)).toCharArray(),
          false, null, false);
      return authentication;
    } catch (IOException e) {
      throw new Error(e); // can't happen
    }
  else
    return null; // unexpected authentication type
}

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

@Override
  public SVNAuthentication createSVNAuthentication(String kind) {
    if (kind.equals(ISVNAuthenticationManager.SSL)) {
      try {
        return new SVNSSLAuthentication(
          Base64.decode(certificate.getPlainText().toCharArray()),
          Scrambler.descramble(password), false);
      } catch (IOException e) {
        throw new Error(e); // can't happen
      }
    } else {
      return null; // unexpected authentication type
    }
  }
}

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

/**
 * Returns null if fails to decrypt properly.
 */
public static String unprotect(String data) {
  if(data==null)      return null;
  try {
    Cipher cipher = Secret.getCipher(ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, DES_KEY);
    String plainText = new String(cipher.doFinal(Base64.decode(data.toCharArray())), "UTF-8");
    if(plainText.endsWith(MAGIC))
      return plainText.substring(0,plainText.length()-3);
    return null;
  } catch (GeneralSecurityException e) {
    return null;
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  } catch (IOException e) {
    return null;
  }
}

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

private String tryRewrite(String s) throws IOException, InvalidKeyException {
  if (s.length()<24)
    return s;   // Encrypting "" in Secret produces 24-letter characters, so this must be the minimum length
  if (!isBase64(s))
    return s;   // decode throws IOException if the input is not base64, and this is also a very quick way to filter
  byte[] in;
  try {
    in = Base64.decode(s.toCharArray());
  } catch (IOException e) {
    return s;   // not a valid base64
  }
  cipher.init(Cipher.DECRYPT_MODE, key);
  Secret sec = HistoricalSecrets.tryDecrypt(cipher, in);
  if(sec!=null) // matched
    return sec.getEncryptedValue(); // replace by the new encrypted value
  else // not encrypted with the legacy key. leave it unmodified
    return s;
}

代码示例来源: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: org.jvnet.hudson.main/hudson-core

X509Certificate c = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(Base64.decode(cert.toString().toCharArray())));
    c.checkValidity();
    certs.add(c);
String computedDigest = new String(Base64.encode(sha1.digest()));
String providedDigest = signature.getString("digest");
if (!computedDigest.equalsIgnoreCase(providedDigest)) {
if (!sig.verify(Base64.decode(signature.getString("signature").toCharArray()))) {
  LOGGER.severe("Signature in the update center doesn't match with the certificate");
  return false;

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

/**
 * Reverse operation of {@link #getEncryptedValue()}. Returns null
 * if the given cipher text was invalid.
 */
public static Secret decrypt(String data) {
  if(data==null)      return null;
  try {
    Cipher cipher = getCipher("AES");
    cipher.init(Cipher.DECRYPT_MODE, getKey());
    String plainText = new String(cipher.doFinal(Base64.decode(data.toCharArray())), "UTF-8");
    if(plainText.endsWith(MAGIC))
      return new Secret(plainText.substring(0,plainText.length()-MAGIC.length()));
    return null;
  } catch (GeneralSecurityException e) {
    return null;
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  } catch (IOException e) {
    return null;
  }
}

代码示例来源: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: jenkinsci/jenkins

if(!isValidData(data))      return null;
    payload = Base64.decode(data.substring(1, data.length()-1).toCharArray());
  } catch (IOException e) {
    return null;
      return new Secret(text, iv);
    default:
      return null;

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

byte[] payload;
try {
  payload = Base64.decode(data.substring(1, data.length()-1).toCharArray());
} catch (IOException e) {
  return null;
    return new Secret(text, iv);
  default:
    return null;

代码示例来源: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.hudsonci.plugins/subversion

@Override
  public SVNAuthentication createSVNAuthentication(String kind) {
    if (kind.equals(ISVNAuthenticationManager.SSL)) {
      try {
        return new SVNSSLAuthentication(
          Base64.decode(certificate.getPlainText().toCharArray()),
          Scrambler.descramble(password), false);
      } catch (IOException e) {
        throw new Error(e); // can't happen
      }
    }
    return null; // unexpected authentication type
  }
}

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

/*package*/ static Secret decrypt(String data, CryptoConfidentialKey key) throws IOException, GeneralSecurityException {
  byte[] in = Base64.decode(data.toCharArray());
  Secret s = tryDecrypt(key.decrypt(), in);
  if (s!=null)    return s;
  // try our historical key for backward compatibility
  Cipher cipher = Secret.getCipher("AES");
  cipher.init(Cipher.DECRYPT_MODE, getLegacyKey());
  return tryDecrypt(cipher, in);
}

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

private String tryRewrite(String s) throws IOException, InvalidKeyException {
  if (s.length()<24)
    return s;   // Encrypting "" in Secret produces 24-letter characters, so this must be the minimum length
  if (!isBase64(s))
    return s;   // decode throws IOException if the input is not base64, and this is also a very quick way to filter
  byte[] in;
  try {
    in = Base64.decode(s.toCharArray());
  } catch (IOException e) {
    return s;   // not a valid base64
  }
  cipher.init(Cipher.DECRYPT_MODE, key);
  Secret sec = HistoricalSecrets.tryDecrypt(cipher, in);
  if(sec!=null) // matched
    return sec.getEncryptedValue(); // replace by the new encrypted value
  else // not encrypted with the legacy key. leave it unmodified
    return s;
}

代码示例来源: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: hudson/hudson-2.x

X509Certificate c = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(Base64.decode(cert.toString().toCharArray())));
    c.checkValidity();
    certs.add(c);
String computedDigest = new String(Base64.encode(sha1.digest()));
String providedDigest = signature.getString("digest");
if (!computedDigest.equalsIgnoreCase(providedDigest)) {
if (!sig.verify(Base64.decode(signature.getString("signature").toCharArray()))) {
  LOGGER.severe("Signature in the update center doesn't match with the certificate");
  return false;

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

/**
 * Reverse operation of {@link #getEncryptedValue()}. Returns null
 * if the given cipher text was invalid.
 */
public static Secret decrypt(String data) {
  if(data==null)      return null;
  try {
    Cipher cipher = getCipher("AES");
    cipher.init(Cipher.DECRYPT_MODE, getKey());
    String plainText = new String(cipher.doFinal(Base64.decode(data.toCharArray())), "UTF-8");
    if(plainText.endsWith(MAGIC))
      return new Secret(plainText.substring(0,plainText.length()-MAGIC.length()));
    return null;
  } catch (GeneralSecurityException e) {
    return null;
  } catch (UnsupportedEncodingException e) {
    throw new Error(e); // impossible
  } catch (IOException e) {
    return null;
  }
}

相关文章