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

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

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

Base64.decode介绍

暂无

代码示例

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

/**
 * Makes sure that the given string is a base64 encoded text.
 *
 * @param allowWhitespace
 *      if you allow whitespace (CR,LF,etc) in base64 encoding
 * @param allowEmpty
 *      Is empty string allowed?
 * @param errorMessage
 *      Error message.
 * @since 1.305
 */
public static FormValidation validateBase64(String value, boolean allowWhitespace, boolean allowEmpty, String errorMessage) {
  try {
    String v = value;
    if(!allowWhitespace) {
      if(v.indexOf(' ')>=0 || v.indexOf('\n')>=0)
        return error(errorMessage);
    }
    v=v.trim();
    if(!allowEmpty && v.length()==0)
      return error(errorMessage);
    com.trilead.ssh2.crypto.Base64.decode(v.toCharArray());
    return ok();
  } catch (IOException e) {
    return error(errorMessage);
  }
}

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

private ConsoleAnnotator<T> createAnnotator(StaplerRequest req) throws IOException {
  try {
    String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null;
    if (base64!=null) {
      Cipher sym = PASSING_ANNOTATOR.decrypt();
      ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
          new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)),
          Jenkins.getInstance().pluginManager.uberClassLoader);
      try {
        long timestamp = ois.readLong();
        if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
          // don't deserialize something too old to prevent a replay attack
          return (ConsoleAnnotator)ois.readObject();
      } finally {
        ois.close();
      }
    }
  } catch (ClassNotFoundException e) {
    throw new IOException(e);
  }
  // start from scratch
  return ConsoleAnnotator.initial(context);
}

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

protected void check() throws IOException, ServletException {
  try {
    String v = request.getParameter("value");
    if(!allowWhitespace) {
      if(v.indexOf(' ')>=0 || v.indexOf('\n')>=0) {
        fail();
        return;
      }
    }
    v=v.trim();
    if(!allowEmpty && v.length()==0) {
      fail();
      return;
    }
    
    com.trilead.ssh2.crypto.Base64.decode(v.toCharArray());
    ok();
  } catch (IOException e) {
    fail();
  }
}

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

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

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

if (signature.verify(Base64.decode(providedSignature.toCharArray()))) {
  return true;

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

X509Certificate c = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(Base64.decode(cert.toString().toCharArray())));
try {
  c.checkValidity();

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

private static byte[] decodeBase64(String s) throws IOException {
  return Base64.decode(s.toCharArray());
}

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

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: org.jvnet.hudson.main/hudson-core

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: org.jenkins-ci.main/jenkins-core

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: org.jvnet.hudson.main/hudson-core

/**
 * 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: 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: 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: 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: 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.jenkins-ci.main/jenkins-core

/*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);
}

相关文章