當前位置: 首頁>>代碼示例>>Java>>正文


Java Base64.decode方法代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:symphonyoss,項目名稱:app-auth-example,代碼行數:23,代碼來源:SecurityKeyUtils.java

示例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;
}
 
開發者ID:mvetsch,項目名稱:JWT4B,代碼行數:17,代碼來源:AlgorithmLinker.java

示例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);
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:22,代碼來源:SecurityUtils.java

示例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);
    }
}
 
開發者ID:americanexpress,項目名稱:amex-api-java-client-core,代碼行數:17,代碼來源:EncryptionUtility.java

示例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);
        }
    }
 
開發者ID:americanexpress,項目名稱:amex-api-java-client-core,代碼行數:23,代碼來源:EncryptionUtility.java

示例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");
	}
}
 
開發者ID:LuatixHQ,項目名稱:openex-worker,代碼行數:17,代碼來源:EmailPgp.java

示例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
        }
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:24,代碼來源:ParsingTest.java

示例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;
  }
}
 
開發者ID:cityzendata,項目名稱:warp10-platform,代碼行數:19,代碼來源:OSSKeyStore.java

示例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());
}
 
開發者ID:thangbn,項目名稱:Direct-File-Downloader,代碼行數:23,代碼來源:PEMReader.java

示例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);
    }
}
 
開發者ID:americanexpress,項目名稱:amex-api-java-client-core,代碼行數:18,代碼來源:EncryptionUtility.java

示例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);
}
 
開發者ID:kaikramer,項目名稱:keystore-explorer,代碼行數:29,代碼來源:Spkac.java

示例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;
	}

}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:23,代碼來源:IcpbrServiceImpl.java

示例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("私鑰數據為空");
    }
}
 
開發者ID:wenzhucjy,項目名稱:GeneralUtils,代碼行數:25,代碼來源:RSAHelper.java

示例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;
	}
}
 
開發者ID:bluecrystalsign,項目名稱:signer-source,代碼行數:19,代碼來源:ServiceFacade.java

示例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 );
	}
}
 
開發者ID:AcademicTorrents,項目名稱:AcademicTorrents-Downloader,代碼行數:20,代碼來源:StringEncrypter.java


注:本文中的org.bouncycastle.util.encoders.Base64.decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。