当前位置: 首页>>代码示例>>Java>>正文


Java Base64.toBase64String方法代码示例

本文整理汇总了Java中org.bouncycastle.util.encoders.Base64.toBase64String方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.toBase64String方法的具体用法?Java Base64.toBase64String怎么用?Java Base64.toBase64String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.util.encoders.Base64的用法示例。


在下文中一共展示了Base64.toBase64String方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encryptReply

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public EncryptedResponsePacket encryptReply(String aesKey, InputStream plaintext) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException {
    byte[] keyBytes = Base64.decode(aesKey);

    SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");

    Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", "BC");
    cipher.init(Cipher.ENCRYPT_MODE, key, new SecureRandom());
    byte[] iv = cipher.getIV();

    ByteArrayOutputStream encrypted = new ByteArrayOutputStream();


    CipherOutputStream cOut = new CipherOutputStream(encrypted, cipher);
    Streams.pipeAll(plaintext, cOut);
    cOut.close();

    EncryptedResponsePacket packet = new EncryptedResponsePacket();
    packet.iv = Base64.toBase64String(iv);
    packet.mode = "ccm";
    packet.ct = Base64.toBase64String(encrypted.toByteArray());

    return packet;
}
 
开发者ID:Tethik,项目名称:whistleblower,代码行数:24,代码来源:CryptographyHandler.java

示例2: randomKeyBase64

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static String randomKeyBase64() {
	Key key = null;
	SecureRandom rand = new SecureRandom();
	KeyGenerator generator;
	try {
		generator = KeyGenerator.getInstance("AES");
		generator.init(rand);
		generator.init(128);
		key = generator.generateKey();
	} catch (NoSuchAlgorithmException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	return new String(Base64.toBase64String(key.getEncoded()));
}
 
开发者ID:openegovplatform,项目名称:OEPv2,代码行数:17,代码来源:SecurityUtil.java

示例3: checksum

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private String checksum(InputStream is) throws IOException {
    SHA256.Digest hash = new SHA256.Digest();
    int nRead;
    byte[] data = new byte[16384];

    while ((nRead = is.read(data, 0, data.length)) != -1) {
        hash.update(data, 0, nRead);
    }
    return Base64.toBase64String(hash.digest());
}
 
开发者ID:Tethik,项目名称:whistleblower,代码行数:11,代码来源:JavascriptVerifier.java

示例4: sign

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static String sign(final String string) throws CodingException {
  try {
    return Base64.toBase64String(sign(string.getBytes("UTF-8"))); //$NON-NLS-1$
  } catch (final UnsupportedEncodingException exception) {
    throw new CodingException(exception.getMessage(), exception);
  }
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:8,代码来源:CryptoUtilities.java

示例5: toString

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String toString() {
	try {
		return Base64.toBase64String((byte[]) toSignedData()
				.getEncoded());
	} catch (CertificateEncodingException
			| OperatorCreationException | CMSException
			| InvalidKeyException | SignatureException
			| NoSuchAlgorithmException | NoSuchProviderException
			| IOException e) {
		throw Throwables.propagate(e);
	}
}
 
开发者ID:NibiruOS,项目名称:afip,代码行数:14,代码来源:LoginTicketRequest.java

示例6: main

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static void main(String[] args) {
    String text = "text";
    byte[] textBytes = text.getBytes();
    String textEncoded = Base64.toBase64String(textBytes);
    byte[] decodedBytes = Base64.decode(textEncoded);
    Arrays.equals(textBytes, decodedBytes);
}
 
开发者ID:flbaue,项目名称:jCryptTool,代码行数:8,代码来源:Base64Experiment.java

示例7: encryptString

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String encryptString(final String string, final String password) throws EncryptionFailedException {
    try {
        final byte[] salt = generateSalt();
        final byte[] key = generateKey(password, salt);
        final byte[] iv = generateIV();
        final byte[] outputInitBlock = generateOutputInitBlock(salt, iv);

        final PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
                new CBCBlockCipher(new AESEngine()), new PKCS7Padding());

        final KeyParameter keyParam = new KeyParameter(key);
        final CipherParameters params = new ParametersWithIV(keyParam, iv);
        cipher.init(true, params);

        final byte in[] = string.getBytes();
        final byte out[] = new byte[cipher.getOutputSize(in.length)];
        final int len1 = cipher.processBytes(in, 0, in.length, out, 0);

        cipher.doFinal(out, len1);

        final byte[] result = Arrays.concatenate(outputInitBlock, out);

        return Base64.toBase64String(result);
    } catch (InvalidKeySpecException | NoSuchAlgorithmException | InvalidCipherTextException e) {
        throw new EncryptionFailedException(e);
    }
}
 
开发者ID:flbaue,项目名称:jCryptTool,代码行数:29,代码来源:AesEncryptionService.java

示例8: getMessageImprintDigestBase64

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String getMessageImprintDigestBase64() {
    return Base64.toBase64String(timeStampToken.getTimeStampInfo().getMessageImprintDigest());
}
 
开发者ID:demoiselle,项目名称:signer,代码行数:4,代码来源:Timestamp.java

示例9: getBase64Signature

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String getBase64Signature() {
    return Base64.toBase64String(this.getRawSignature());
}
 
开发者ID:laverca,项目名称:laverca,代码行数:5,代码来源:CmsSignature.java

示例10: asDataUri

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private final static String asDataUri(byte data[])
{ return "data:image/jpeg;base64,"+Base64.toBase64String(data); }
 
开发者ID:kbsriram,项目名称:keypan,代码行数:3,代码来源:CLookupServlet.java

示例11: byteArrayToString

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * Converts a byte array into a Base64 encoded string.
 *
 * @param bytes The byte array to convert.
 *
 * @return The Base64 encoded string.
 */
public static String byteArrayToString(byte[] bytes) {
    return Base64.toBase64String(bytes);
}
 
开发者ID:michaelnetter,项目名称:dracoon-dropzone,代码行数:11,代码来源:CryptoUtils.java

示例12: sign

import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * @param privateKey
 * @param message    UTF-8 encoded message to sign
 * @return Base64 encoded signature
 * @throws SignatureException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeyException
 */
public static String sign(PrivateKey privateKey, String message) throws CryptoException {
    byte[] sigAsBytes = sign(privateKey, message.getBytes(Charsets.UTF_8));
    return Base64.toBase64String(sigAsBytes);
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:13,代码来源:Sig.java


注:本文中的org.bouncycastle.util.encoders.Base64.toBase64String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。