org.bouncycastle.util.encoders.Base64.decode()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(407)

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

Base64.decode介绍

[英]decode the base 64 encoded String data - whitespace will be ignored.
[中]解码base64编码的字符串数据-空白将被忽略。

代码示例

代码示例来源:origin: apache/nifi

private byte[] decode(String encoded) throws DecoderException {
  if (this.encoding.equalsIgnoreCase("HEX")) {
    return Hex.decodeHex(encoded.toCharArray());
  } else {
    return Base64.decode(encoded);
  }
}

代码示例来源:origin: floragunncom/search-guard

private static byte[] readPrivateKey(InputStream in) throws KeyException {
  String content;
  try {
    content = readContent(in);
  } catch (IOException e) {
    throw new KeyException("failed to read key input stream", e);
  }
  Matcher m = KEY_PATTERN.matcher(content);
  if (!m.find()) {
    throw new KeyException("could not find a PKCS #8 private key in input stream" +
        " (see http://netty.io/wiki/sslcontextbuilder-and-private-key.html for more information)");
  }
  return Base64.decode(m.group(1));
}

代码示例来源:origin: cloudfoundry/uaa

public UaaAuthenticationDetails(HttpServletRequest request, String clientId) {
  WebAuthenticationDetails webAuthenticationDetails = new WebAuthenticationDetails(request);
  this.origin = webAuthenticationDetails.getRemoteAddress();
  this.sessionId = webAuthenticationDetails.getSessionId();
  if (clientId == null) {
    this.clientId = request.getParameter("client_id");
    if(!StringUtils.hasText(this.clientId)) {
      String authHeader = request.getHeader("Authorization");
      if(StringUtils.hasText(authHeader) && authHeader.startsWith("Basic ")) {
        String decodedCredentials = new String(Base64.decode(authHeader.substring("Basic ".length())));
        String[] split = decodedCredentials.split(":");
        if (split == null || split.length == 0)
          throw new BadCredentialsException("Invalid basic authentication token");
        this.clientId = split[0];
      }
    }
  } else {
    this.clientId = clientId;
  }
  this.addNew = Boolean.parseBoolean(request.getParameter(ADD_NEW));
  this.loginHint = UaaLoginHint.parseRequestParameter(request.getParameter("login_hint"));
  this.parameterMap = request.getParameterMap();
}

代码示例来源:origin: apache/nifi

byte[] iv = Base64.decode(IV_B64);
if (iv.length < IV_LENGTH) {
  throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes");
  byte[] cipherBytes = Base64.decode(CIPHERTEXT_B64);

代码示例来源:origin: apache/cloudstack

private static byte[] decode(String input) throws UnsupportedEncodingException {
    return Base64.decode(input.getBytes("UTF-8"));
  }
}

代码示例来源:origin: apache/cloudstack

/**
 * Decodes base64 encoded public key to PublicKey
 * @param publicKey encoded public key string
 * @return returns PublicKey
 */
public static PublicKey decodePublicKey(String publicKey) {
  byte[] sigBytes = org.bouncycastle.util.encoders.Base64.decode(publicKey);
  X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(sigBytes);
  KeyFactory keyFactory = CertUtils.getKeyFactory();
  if (keyFactory == null)
    return null;
  try {
    return keyFactory.generatePublic(x509KeySpec);
  } catch (InvalidKeySpecException e) {
    s_logger.error("Unable to create PublicKey from PublicKey string:" + e.getMessage());
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

/**
 * Decodes base64 encoded private key to PrivateKey
 * @param privateKey encoded private key string
 * @return returns PrivateKey
 */
public static PrivateKey decodePrivateKey(String privateKey) {
  byte[] sigBytes = org.bouncycastle.util.encoders.Base64.decode(privateKey);
  PKCS8EncodedKeySpec pkscs8KeySpec = new PKCS8EncodedKeySpec(sigBytes);
  KeyFactory keyFactory = CertUtils.getKeyFactory();
  if (keyFactory == null)
    return null;
  try {
    return keyFactory.generatePrivate(pkscs8KeySpec);
  } catch (InvalidKeySpecException e) {
    s_logger.error("Unable to create PrivateKey from privateKey string:" + e.getMessage());
  }
  return null;
}

代码示例来源:origin: apache/cloudstack

} else {
  realPassword = storedPassword[1];
  salt = Base64.decode(storedPassword[0]);

代码示例来源:origin: io.ifar.skid-road/skid-road

/**
 * Create a new instance wrapped around the supplied {@link io.ifar.skidroad.awssdk.S3Storage}.
 * @param storage a configured (and started) S3 access instance
 * @param masterKey the master encryption key to use in decrypting files.
 * @param masterIV the master IV (may be null) to use in decrypting files whose key was encoded with the legacy algorithm which does not embed the master IV.
 */
public StreamingAccess(S3Storage storage, String masterKey, String masterIV) {
  this.storage = storage;
  this.masterKey = Base64.decode(masterKey);
  this.masterIV = masterIV == null ? null : Base64.decode(masterIV);
}

代码示例来源:origin: OPCFoundation/UA-Java-Legacy

/**
 * <p>base64Decode.</p>
 *
 * @param string a {@link java.lang.String} object.
 * @return an array of byte.
 */
public static byte[] base64Decode(String string) {
  return Base64.decode(string);
}

代码示例来源:origin: com.dracoon/dracoon-crypto-sdk

/**
 * Converts a Base64 encoded string into a byte array.
 *
 * @param base64String The string to convert.
 *
 * @return The decoded byte array.
 */
public static byte[] stringToByteArray(String base64String) {
  return Base64.decode(base64String);
}

代码示例来源:origin: eBay/UAF

/***
 * Example implementation. It only knows to verify SHA256withEC algorithm.
 */
public boolean validate(String cert, String signedData, String signature)
    throws NoSuchAlgorithmException, IOException, Exception {
  byte[] certBytes = Base64.decode(cert);
  byte[] signedDataBytes = Base64.decode(signedData);
  byte[] signatureBytes = Base64.decode(signature);
  return validate(certBytes, signedDataBytes, signatureBytes);
}

代码示例来源:origin: org.jenkins-ci.plugins/bouncycastle-api

/**
 * Decodes a base 64 string into a {@link byte[]}
 * 
 * @param data to be decoded
 * @return decoded data
 */
@Nonnull
private static byte[] decodeBase64(@Nonnull String data) {
  return Base64.decode(data);
}

代码示例来源:origin: DanielKrawisz/Shufflepuff

public static PrivateKey loadPrivateKey(String key64) throws GeneralSecurityException {
 byte[] clear = Base64.decode(key64);
 PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(clear);
 KeyFactory fact = KeyFactory.getInstance("ECDSA", new BouncyCastleProvider());
 PrivateKey priv = fact.generatePrivate(keySpec);
 Arrays.fill(clear, (byte) 0);
 return priv;
}

代码示例来源:origin: DanielKrawisz/Shufflepuff

public static PublicKey loadPublicKey(String stored) throws GeneralSecurityException {
 byte[] data = Base64.decode(stored);
 X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
 KeyFactory fact = KeyFactory.getInstance("ECDSA", new BouncyCastleProvider());
 try {
   return fact.generatePublic(spec);
 } catch (InvalidKeySpecException e) {
   throw new IllegalArgumentException(e);
 }
}

代码示例来源:origin: OPCFoundation/UA-Java-Legacy

/** {@inheritDoc} */
@Override
public byte[] base64Decode(String string) {
  return Base64.decode(StringUtils.removeWhitespace(string));
}

代码示例来源:origin: org.italiangrid/voms-api-java

public static byte[] decode(String s) {
 if (s.indexOf('\n') != -1) {
  return Base64.decode(s.trim().replaceAll("\n", ""));
 } else
  return mydecode(s);
}

代码示例来源:origin: OPCFoundation/UA-Java-Legacy

/** {@inheritDoc} */
@Override
public byte[] base64Decode(String string) {
  return Base64.decode(StringUtils.removeWhitespace(string));
}

代码示例来源:origin: jpos/jPOS-EE

@Override
public boolean check (String seed, String secret, String hash) throws Exception {
  byte[] b = Base64.decode(hash);
  byte[] salt = new byte[ONE.getSalt().length];
  System.arraycopy (b, 1, salt, 0, salt.length);
  String computedHash = ONE.hash(seed, secret, ONE.getSalt(salt));
  return computedHash.equals(hash);
}

代码示例来源:origin: eBay/UAF

@Test
public void basic() {
  Notary notary = new NotaryImpl();
  RegistrationRequest regReq = new RegistrationRequestGeneration().createRegistrationRequest("Username", notary);
  
  String serverData = regReq.header.serverData;
  serverData = new String (Base64.decode(serverData));
  assertTrue(notary.verify(serverData,serverData));
  assertTrue(RegistrationRequestGeneration.APP_ID.equals(regReq.header.appID));
  logger.info(gson.toJson(regReq));
}

相关文章