本文整理汇总了Java中org.bouncycastle.util.encoders.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.encoders.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseRSAPublicKey
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
* Creates a RSA Public Key from a PEM String
*
* @param pemPublicKey public key in PEM format
* @return a RSA public key
*/
public static PublicKey parseRSAPublicKey(final String pemPublicKey)
throws GeneralSecurityException {
try {
String publicKeyString = pemPublicKey
.replace(PEM_PUBLIC_START, "")
.replace(PEM_PUBLIC_END, "")
.replaceAll("\\s", "");
byte[] keyBytes = Base64.decode(publicKeyString.getBytes("UTF-8"));
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(spec);
} catch (InvalidKeySpecException | NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new GeneralSecurityException(e);
}
}
示例2: generatePrivateKeyFromString
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private static PrivateKey generatePrivateKeyFromString(String key, String algorithm) {
PrivateKey privateKey = null;
if(key.length()>1){
key = key.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "")
.replaceAll("\\s+", "").replaceAll("\\r+", "").replaceAll("\\n+", "");
byte[] keyByteArray = Base64.decode(key);
try {
KeyFactory kf = KeyFactory.getInstance(algorithm);
EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyByteArray);
privateKey = kf.generatePrivate(keySpec);
} catch (Exception e) {
ConsoleOut.output(e.getMessage());
}
}
return privateKey;
}
示例3: DecryptMsg
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
* 解码
* @param byteMsg base64格式的byte数组
* @return 解码后的byte数组
* @since 1.0
*/
public byte[] DecryptMsg(byte[] byteMsg) {
if (byteMsg == null || byteMsg.length == 0) {
return new byte[]{};
}
byte[] msg = Base64.decode(byteMsg);
byte[] pDecData = AESUtils.decrypt(msg);
if (pDecData == null || pDecData.length < 4) {
return new byte[]{};
}
byte[] lenbytes = Arrays.copyOfRange(pDecData, pDecData.length - 4, pDecData.length);
int nInLen = CommonUtils.byteArray2int(lenbytes);
return Arrays.copyOf(pDecData, nInLen);
}
示例4: decrypt
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String decrypt(String keyStr, String encryptedData) {
try {
byte[] decodedKey = Base64.decode(keyStr);
SecretKeySpec key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
JWEDecrypter decrypter = new AESDecrypter(key);
decrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance());
JWEObject jweObject = JWEObject.parse(encryptedData);
jweObject.decrypt(decrypter);
return jweObject.getPayload().toBase64URL().decodeToString();
} catch (Exception e) {
throw new CryptoException("Exception decrypting field: " + e.getMessage(), e);
}
}
示例5: encrypt
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String encrypt(String data, String keyId, String aesKey) {
try {
byte[] keyBytes = Base64.decode(aesKey);
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
JWEAlgorithm jweAlgorithm = JWEAlgorithm.A256KW;
EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM;
JWEHeader.Builder headerBuilder = new JWEHeader.Builder(jweAlgorithm, encryptionMethod);
headerBuilder.keyID(keyId);
JWEHeader header = headerBuilder.build();
JWEEncrypter encrypter = new AESEncrypter(secretKey);
encrypter.getJCAContext().setProvider(BouncyCastleProviderSingleton.getInstance());
JWEObject jweObject = new JWEObject(header, new Payload(data));
jweObject.encrypt(encrypter);
return jweObject.serialize();
} catch (Exception e) {
throw new CryptoException("Exception encrypting data: " + e.getMessage(), e);
}
}
示例6: pgpKeyFromExchange
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private PGPPublicKey pgpKeyFromExchange(Exchange exchange) throws IOException {
String user = exchange.getIn().getHeader("To", String.class);
String base64PgpKey = exchange.getIn().getHeader("PgpKey", String.class);
if (base64PgpKey != null) {
byte[] pgpKey = Base64.decode(base64PgpKey);
InputStream in = new ByteArrayInputStream(pgpKey);
InputStream decoderStream = PGPUtil.getDecoderStream(in);
PGPPublicKeyRing keyRing = new JcaPGPPublicKeyRing(decoderStream);
Spliterator<PGPPublicKey> splitIterator = spliteratorUnknownSize(keyRing.getPublicKeys(), Spliterator.ORDERED);
Stream<PGPPublicKey> targetStream = StreamSupport.stream(splitIterator, false);
return targetStream.filter(pgpPublicKey -> pgpPublicKey.isEncryptionKey() && !pgpPublicKey.isMasterKey())
.findFirst().orElseThrow(() -> new IllegalArgumentException(user + " error: Invalid PGP public key"));
} else {
throw new IllegalArgumentException(user + " error: PGP key not provided");
}
}
示例7: parserTest
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private void parserTest()
{
for (int i = 0; i != streams.length; i++)
{
ASN1StreamParser aIn = new ASN1StreamParser(Base64.decode(streams[i]));
try
{
Object obj;
while ((obj = aIn.readObject()) != null)
{
}
fail("bad stream parsed successfully!");
}
catch (IOException e)
{
// ignore
}
}
}
示例8: decodeKey
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public byte[] decodeKey(String encoded) {
if (null == encoded) {
return null;
}
if (encoded.startsWith("hex:")) {
return Hex.decode(encoded.substring(4));
} else if (encoded.startsWith("base64:")) {
return Base64.decode(encoded.substring(7));
} else if (encoded.startsWith("wrapped:")) {
if (null == this.masterKey) {
throw new RuntimeException("Master Key not retrieved from OSS, aborting.");
}
return CryptoHelper.unwrapBlob(this.masterKey, decodeKey(encoded.substring(8)));
} else {
return null;
}
}
示例9: readBytes
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private byte[] readBytes(String endMarker)
throws IOException
{
String line;
StringBuffer buf = new StringBuffer();
while ((line = readLine()) != null)
{
if (line.indexOf(endMarker) != -1)
{
break;
}
buf.append(line.trim());
}
if (line == null)
{
throw new IOException(endMarker + " not found");
}
return Base64.decode(buf.toString());
}
示例10: getKey
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private Key getKey(String algorithm, String keyStr) {
try {
if ("HS256".equals(algorithm)) {
//return Secret Key
byte[] decodedKey = Base64.decode(keyStr);
return new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
} else {
//return private key
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(Base64.decode(keyStr)));
}
} catch(Exception e) {
throw new CryptoException("Exception creating key: " + e.getMessage(), e);
}
}
示例11: Spkac
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
* Load a SPKAC.
*
* @param is
* Stream to load from
* @throws IOException
* If an I/O problem occurs
* @throws SpkacMissingPropertyException
* If no subject is present in SPKAC
* @throws SpkacException
* If load fails
*/
public Spkac(InputStream is) throws IOException, SpkacException {
Properties properties = readProperties(is);
if (!properties.containsKey(SPKAC_PROPERTY)) {
throw new SpkacMissingPropertyException(MessageFormat.format(
res.getString("SpkacNoIncludeRequiredProperty.exception.message"), SPKAC_PROPERTY));
}
subject = getSubject(properties);
String spkacProperty = properties.getProperty(SPKAC_PROPERTY);
derSpkac = Base64.decode(spkacProperty);
decodeSpkac(derSpkac);
}
示例12: hashSignedAttribADRB10
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String hashSignedAttribADRB10(String origHashB64, Date signingTime,
String x509B64) throws Exception {
logger.debug("hashSignedAttribSha1: " + "\norigHashB64 (" + origHashB64
+ ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64("
+ x509B64 + ")");
try {
byte[] origHash = Base64.decode(origHashB64);
byte[] x509 = Base64.decode(x509B64);
X509Certificate cert = loadCertFromB64(x509);
byte[] ret = ccServ.hashSignedAttribSha1(origHash, signingTime,
cert);
return new String( Base64.encode(ret) );
} catch (Exception e) {
logger.error("ERRO: ", e);
throw e;
}
}
示例13: loadPrivateKeyPEM
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
* 加载 PKCS#8 编码的 pem 格式私钥文件
*
* @param privateKeyStr 私钥
* @throws Exception
*/
public void loadPrivateKeyPEM(String privateKeyStr) throws Exception {
try {
// Base64 解码
byte[] e = Base64.decode(privateKeyStr);
// 使用 PKCS#8 标准作为密钥规范管理的编码格式
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(e);
// 实例化KeyFactory对象,并指定 RSA 算法
KeyFactory keyFactory = KeyFactory.getInstance(SIGN_ALGORITHMS);
// 获得PrivateKey对象
this.privateKey = keyFactory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException var5) {
throw new Exception("无此算法");
} catch (InvalidKeySpecException var6) {
throw new Exception("私钥非法");
} catch (NullPointerException var7) {
throw new Exception("私钥数据为空");
}
}
示例14: hashSignedAttribADRB21
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String hashSignedAttribADRB21(String origHashB64, Date signingTime, String x509B64) throws Exception {
// logger.debug("hashSignedAttribSha256: " + "\norigHashB64 (" +
// origHashB64
// + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64("
// + x509B64 + ")");
try {
byte[] origHash = Base64.decode(origHashB64);
byte[] x509 = Base64.decode(x509B64);
X509Certificate cert = certServ.createFromB64(x509);
byte[] ret = ccServ.hashSignedAttribSha256(origHash, signingTime, cert);
return new String(Base64.encode(ret));
} catch (Exception e) {
// ;logger.error("ERRO: ", e);
throw e;
}
}
示例15: decrypt
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String decrypt( String encryptedString ) throws EncryptionException
{
if ( encryptedString == null || encryptedString.trim().length() <= 0 )
throw new IllegalArgumentException( "encrypted string was null or empty" );
try
{
SecretKey key = keyFactory.generateSecret( keySpec );
cipher.init( Cipher.DECRYPT_MODE, key );
byte[] cleartext = Base64.decode( encryptedString );
byte[] ciphertext = cipher.doFinal( cleartext );
return bytes2String( ciphertext );
}
catch (Exception e)
{
throw new EncryptionException( e );
}
}