本文整理汇总了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;
}
示例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()));
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例8: getMessageImprintDigestBase64
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
public String getMessageImprintDigestBase64() {
return Base64.toBase64String(timeStampToken.getTimeStampInfo().getMessageImprintDigest());
}
示例9: getBase64Signature
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Override
public String getBase64Signature() {
return Base64.toBase64String(this.getRawSignature());
}
示例10: asDataUri
import org.bouncycastle.util.encoders.Base64; //导入方法依赖的package包/类
private final static String asDataUri(byte data[])
{ return "data:image/jpeg;base64,"+Base64.toBase64String(data); }
示例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);
}
示例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);
}