本文整理了Java中org.bouncycastle.util.encoders.Base64.encode()
方法的一些代码示例,展示了Base64.encode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encode()
方法的具体详情如下:
包路径:org.bouncycastle.util.encoders.Base64
类名称:Base64
方法名:encode
[英]encode the input data producing a base 64 encoded byte array.
[中]对输入数据进行编码,生成一个基64编码字节数组。
代码示例来源:origin: apache/cloudstack
private static String encode(byte[] input) throws UnsupportedEncodingException {
return new String(Base64.encode(input), "UTF-8");
}
代码示例来源:origin: apache/cloudstack
public String encode(String password, byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException {
byte[] passwordBytes = password.getBytes("UTF-8");
byte[] hashSource = new byte[passwordBytes.length + salt.length];
System.arraycopy(passwordBytes, 0, hashSource, 0, passwordBytes.length);
System.arraycopy(salt, 0, hashSource, passwordBytes.length, salt.length);
// 2. Hash the password with the salt
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(hashSource);
byte[] digest = md.digest();
return new String(Base64.encode(digest));
}
代码示例来源:origin: apache/cloudstack
private String generatePassword() throws ServerApiException {
try {
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
final byte bytes[] = new byte[20];
randomGen.nextBytes(bytes);
return new String(Base64.encode(bytes), "UTF-8");
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password");
}
}
代码示例来源:origin: apache/cloudstack
private String generatePassword() throws ServerApiException {
try {
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
final byte bytes[] = new byte[20];
randomGen.nextBytes(bytes);
return new String(Base64.encode(bytes), "UTF-8");
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password");
}
}
}
代码示例来源:origin: apache/cloudstack
@Override
public String encode(String password) {
// 1. Generate the salt
SecureRandom randomGen;
try {
randomGen = SecureRandom.getInstance("SHA1PRNG");
byte salt[] = new byte[s_saltlen];
randomGen.nextBytes(salt);
String saltString = new String(Base64.encode(salt));
String hashString = encode(password, salt);
// 3. concatenate the two and return
return saltString + ":" + hashString;
} catch (NoSuchAlgorithmException e) {
throw new CloudRuntimeException("Unable to hash password", e);
} catch (UnsupportedEncodingException e) {
throw new CloudRuntimeException("Unable to hash password", e);
}
}
代码示例来源:origin: apache/cloudstack
/**
* Returns base64 encoded PublicKey
* @param key PublicKey
* @return public key encoded string
*/
public static String encodePublicKey(PublicKey key) {
try {
KeyFactory keyFactory = CertUtils.getKeyFactory();
if (keyFactory == null) return null;
X509EncodedKeySpec spec = keyFactory.getKeySpec(key, X509EncodedKeySpec.class);
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to get KeyFactory:" + e.getMessage());
}
return null;
}
代码示例来源:origin: apache/cloudstack
/**
* Returns base64 encoded PrivateKey
* @param key PrivateKey
* @return privatekey encoded string
*/
public static String encodePrivateKey(PrivateKey key) {
try {
KeyFactory keyFactory = CertUtils.getKeyFactory();
if (keyFactory == null) return null;
PKCS8EncodedKeySpec spec = keyFactory.getKeySpec(key,
PKCS8EncodedKeySpec.class);
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to get KeyFactory:" + e.getMessage());
}
return null;
}
代码示例来源:origin: redfish64/TinyTravelTracker
/**
* encode the input data producing a base 64 encoded byte array.
*
* @return a byte array containing the base 64 encoded data.
*/
public static byte[] encode(
byte[] data)
{
return encode(data, 0, data.length);
}
代码示例来源:origin: org.jboss.aerogear/aerogear-crypto
@Override
public String encode(byte[] data) {
return new String(org.bouncycastle.util.encoders.Base64.encode(data), CHARSET);
}
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/** {@inheritDoc} */
@Override
public String base64Encode(byte[] bytes) {
try {
return new String(Base64.encode(bytes), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/** {@inheritDoc} */
@Override
public String base64Encode(byte[] bytes) {
try {
return new String(Base64.encode(bytes), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.jenkins-ci.plugins/bouncycastle-api
/**
* Encodes a {@link byte[]} in base 64 string
*
* @param data to be encoded
* @return base 64 formatted string
*/
@Nonnull
private static String encodeBase64(@Nonnull byte[] data) {
return new String(Base64.encode(data), StandardCharsets.UTF_8);
}
代码示例来源:origin: eu.eu-emi.security/canl
public File getCacheFile(URL url)
throws URISyntaxException
{
File dir = new File(diskPath);
byte[] src = url.toURI().toASCIIString().getBytes();
byte[] encoded = Base64.encode(src);
String filename = new String(encoded,CertificateUtils.ASCII) +
suffix + ".der";
return new File(dir, filename);
}
代码示例来源:origin: miltonio/milton2
public static String toState(String providerId, String returnUrl) {
StringBuilder sb = new StringBuilder(providerId);
if (returnUrl != null) {
sb.append("||");
sb.append(returnUrl);
}
byte[] arr = Base64.encode(sb.toString().getBytes());
String encoded = new String(arr);
return encoded;
}
代码示例来源:origin: org.codeartisans.qipki/qipki-crypto
@Override
public String toBase64String( byte[] bytes )
{
try {
return new String( Base64.encode( bytes ), "UTF-8" );
} catch ( UnsupportedEncodingException ex ) {
throw new CryptoFailure( "Unable to encode data in Base64", ex );
}
}
代码示例来源:origin: pl.edu.icm.bwmeta/bwmeta-2-foreign-transformers
private String getAffiliationRef(String affiliation) {
MD5Digest digest = new MD5Digest();
digest.update(affiliation.getBytes(), 0, affiliation.getBytes().length);
byte[] output = new byte[16];
digest.doFinal(output, 0);
return new String(Base64.encode(output));
}
代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on
public static String toBase64String(
byte[] data,
int off,
int length)
{
byte[] encoded = encode(data, off, length);
return Strings.fromByteArray(encoded);
}
代码示例来源:origin: Hive2Hive/Hive2Hive
@Test
public void hashExampleDataTest() {
final String expected = "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=";
String data = "hello world";
byte[] hash = HashUtil.hash(data.getBytes());
String result = new String(Base64.encode(hash));
assertEquals(expected, result);
}
代码示例来源:origin: no.difi.commons/commons-asic
@Override
public void add(String filename, MimeType mimeType) {
DataObjectReferenceType dataObject = new DataObjectReferenceType();
dataObject.setURI(filename);
dataObject.setMimeType(mimeType.toString());
dataObject.setDigestValue(messageDigest.digest());
DigestMethodType digestMethodType = new DigestMethodType();
digestMethodType.setAlgorithm(messageDigestAlgorithm.getUri());
dataObject.setDigestMethod(digestMethodType);
ASiCManifestType.getDataObjectReference().add(dataObject);
logger.debug("Digest: {}", Base64.encode(dataObject.getDigestValue()));
}
代码示例来源:origin: Hive2Hive/Hive2Hive
@Test
public void hashStreamExampleDataTest() throws IOException {
final String expected = "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=";
String data = "hello world";
File file = new File(FileUtils.getTempDirectory(), randomString());
FileUtils.writeStringToFile(file, data);
byte[] hash = HashUtil.hash(file);
String result = new String(Base64.encode(hash));
assertEquals(expected, result);
}
内容来源于网络,如有侵权,请联系作者删除!