本文整理了Java中org.spongycastle.util.encoders.Base64.toBase64String()
方法的一些代码示例,展示了Base64.toBase64String()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.toBase64String()
方法的具体详情如下:
包路径:org.spongycastle.util.encoders.Base64
类名称:Base64
方法名:toBase64String
暂无
代码示例来源:origin: CoinbaseWallet/toshi-headless-client
private void saveIvToFile(final byte[] iv) {
final String toWrite = Base64.toBase64String(iv);
//this.preferences.edit().putString(IV, toWrite).apply();
}
代码示例来源:origin: cternes/openkeepass
@Override
public String write(byte[] value) throws Exception {
return Base64.toBase64String(value);
}
代码示例来源:origin: nebulasio/neb.java
public static String Base64ToString(byte[] data) {
return Base64.toBase64String(data);
}
代码示例来源:origin: cternes/openkeepass
@Override
public String write(UUID value) throws Exception {
if(value == null) {
return Base64.toBase64String(new byte[0]);
}
return Base64.toBase64String(ByteUtils.uuidToBytes(value));
}
代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on
private String annotateRequest(byte[] data)
{
int i = 0;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
// pw.print("-----BEGIN CERTIFICATE REQUEST-----\n");
do
{
if (i + 48 < data.length)
{
pw.print(Base64.toBase64String(data, i, 48));
i += 48;
}
else
{
pw.print(Base64.toBase64String(data, i, data.length - i));
i = data.length;
}
pw.print('\n');
}
while (i < data.length);
// pw.print("-----END CERTIFICATE REQUEST-----\n");
pw.flush();
return sw.toString();
}
代码示例来源:origin: com.madgag.spongycastle/core
public static String toBase64String(
byte[] data,
int off,
int length)
{
byte[] encoded = encode(data, off, length);
return Strings.fromByteArray(encoded);
}
代码示例来源:origin: Multibit-Legacy/multibit-hardware
/**
* <p>Get an SSH key from the compressed EC public key in base64</p>
*
* @param publicKey The ecdsa-sha2-nistp256 EC public key
*
* @return An ssh key-only base64 format of public key from given EC public key
*/
public static String decompressSSHKeyFromNistp256(ECPublicKey publicKey) {
ByteBuffer buffer = ByteBuffer.allocate(104);
buffer.putInt(KEY_PREFIX.getBytes(Charsets.UTF_8).length);
buffer.put(KEY_PREFIX.getBytes(Charsets.UTF_8));
buffer.putInt(CURVE_NAME.getBytes(Charsets.UTF_8).length);
buffer.put(CURVE_NAME.getBytes(Charsets.UTF_8));
byte[] octet = {(byte) 0x04}; // this is special byte for SSH
byte[] x = publicKey.getW().getAffineX().toByteArray(); // get X, Y cords of ECPoint
byte[] y = publicKey.getW().getAffineY().toByteArray();
byte[] x32 = ByteUtils.subArray(x, x.length - 32, x.length); //get last 32 bytes
byte[] y32 = ByteUtils.subArray(y, y.length - 32, y.length);
// Ignore the y32 warning here in Intellij - it's just a naming mismatch in parameters
byte[] data = ByteUtils.concatenate(octet, ByteUtils.concatenate(x32, y32));
buffer.putInt(data.length);
buffer.put(data);
return Base64.toBase64String(buffer.array());
}
代码示例来源:origin: martin-lizner/trezor-ssh-agent
/**
* <p>
* Get an SSH key from the compressed EC public key in base64</p>
*
* @param publicKey The ecdsa-sha2-nistp256 EC public key
*
* @return An ssh key-only base64 format of public key from given EC public
* key
*/
public static String serializeSSHKeyFromNistp256(ECPublicKey publicKey) {
ByteBuffer buffer = ByteBuffer.allocate(104);
buffer.putInt(NISTP256_KEY_PREFIX.getBytes(Charsets.UTF_8).length);
buffer.put(NISTP256_KEY_PREFIX.getBytes(Charsets.UTF_8));
buffer.putInt(NISTP256_CURVE_NAME.getBytes(Charsets.UTF_8).length);
buffer.put(NISTP256_CURVE_NAME.getBytes(Charsets.UTF_8));
byte[] octet = {(byte) 0x04}; // this is special byte for SSH
byte[] x = publicKey.getW().getAffineX().toByteArray(); // get X, Y cords of ECPoint
byte[] y = publicKey.getW().getAffineY().toByteArray();
byte[] x32 = ByteUtils.subArray(x, x.length - 32, x.length); //get last 32 bytes
byte[] y32 = ByteUtils.subArray(y, y.length - 32, y.length);
byte[] data = ByteUtils.concatenate(octet, ByteUtils.concatenate(x32, y32));
buffer.putInt(data.length);
buffer.put(data);
return Base64.toBase64String(buffer.array());
}
代码示例来源:origin: martin-lizner/trezor-ssh-agent
public static String serializeSSHKeyFromEd25519(byte[] pubKey) {
byte[] pubKeyWorking = ByteUtils.clone(pubKey);
if (pubKeyWorking[0] == 0x00) {
pubKeyWorking = ByteUtils.subArray(pubKeyWorking, 1); //strip the first byte
}
byte[] keyTypeFrame = AgentUtils.frameArray(ED25519_KEY_PREFIX.getBytes(Charsets.UTF_8));
byte[] pubKeyFrame = AgentUtils.frameArray(pubKeyWorking);
String serializedKey = Base64.toBase64String(ByteUtils.concatenate(keyTypeFrame, pubKeyFrame)); // easier than nistp256, we do not need to uncompress pubkey to x and y, we just send it compressed as device provided
return ED25519_KEY_PREFIX + " " + serializedKey;
}
代码示例来源:origin: HashEngineering/dashj
public static boolean verifyMessage(PublicKey pubkey, MasternodeSignature vchSig, String strMessage, StringBuilder errorMessage)
{
//int length = Utils.BITCOIN_SIGNED_MESSAGE_HEADER.length()+strMessage.length();
//byte dataToHash [] = (Utils.BITCOIN_SIGNED_MESSAGE_HEADER_BYTES+strMessage).getBytes();
ECKey pubkey2 = null;
try {
//pubkey2 = PublicKey.recoverCompact(Sha256Hash.twiceOf(dataToHash), vchSig);
pubkey2 = ECKey.fromPublicOnly(pubkey.getBytes());
pubkey2.verifyMessage(strMessage.getBytes(), vchSig.getBytes());
//ECKey.verify()
//if(DarkCoinSystem.fDebug && !pubkey.getId().equals(pubkey2.getId()))
// log.info("DarkSendSigner.verifyMessage -- keys don't match: " + pubkey2.getId().toString()+ " " + pubkey.getId().toString());
//return pubkey.getId().equals(pubkey2.getId());
return true;
}
catch(SignatureException x)
{
errorMessage.append("keys don't match - input: "+Utils.HEX.encode(pubkey.getId()));
errorMessage.append(", recovered: " + (pubkey2 != null ? Utils.HEX.encode(pubkey2.getPubKeyHash()) : "null"));
errorMessage.append(",\nmessage: "+ String.valueOf(strMessage));
errorMessage.append(", sig: \n" + Base64.toBase64String(vchSig.getBytes())+ "\n" + x.getMessage());
return false;
}
}
public static boolean verifyMessage1(PublicKey pubkey, MasternodeSignature vchSig, byte[] message, StringBuilder errorMessage)
代码示例来源:origin: HashEngineering/dashj
public static boolean verifyHash(Sha256Hash hash, byte [] pubkeyId, MasternodeSignature vchSig, StringBuilder strErrorRet) {
ECKey pubkeyFromSig;
try {
pubkeyFromSig = ECKey.signedMessageToKey(hash, vchSig.getBytes());
if (pubkeyFromSig == null) {
strErrorRet.append("Error recovering public key.");
return false;
}
if (!Arrays.equals(pubkeyFromSig.getPubKeyHash(), pubkeyId)) {
strErrorRet.append(String.format("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s",
HEX.encode(pubkeyId), HEX.encode(pubkeyFromSig.getPubKeyHash()),
hash.toString(), Base64.toBase64String(vchSig.getBytes())));
return false;
}
return true;
} catch (SignatureException x) {
strErrorRet.append("exception: " + x.getMessage());
return false;
}
}
代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on
public ESTRequest onConnection(Source source, ESTRequest request)
throws IOException
{
//
// Add challenge password from tls unique
//
if (source instanceof TLSUniqueProvider && ((TLSUniqueProvider)source).isTLSUniqueAvailable())
{
PKCS10CertificationRequestBuilder localBuilder = new PKCS10CertificationRequestBuilder(builder);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] tlsUnique = ((TLSUniqueProvider)source).getTLSUnique();
localBuilder.setAttribute(PKCSObjectIdentifiers.pkcs_9_at_challengePassword, new DERPrintableString(Base64.toBase64String(tlsUnique)));
bos.write(annotateRequest(localBuilder.build(contentSigner).getEncoded()).getBytes());
bos.flush();
ESTRequestBuilder reqBuilder = new ESTRequestBuilder(request).withData(bos.toByteArray());
reqBuilder.setHeader("Content-Type", "application/pkcs10");
reqBuilder.setHeader("Content-Transfer-Encoding", "base64");
reqBuilder.setHeader("Content-Length", Long.toString(bos.size()));
return reqBuilder.build();
}
else
{
throw new IOException("Source does not supply TLS unique.");
}
}
});
代码示例来源:origin: martin-lizner/trezor-ssh-agent
String keyTypeProvided = unframeKeyTypeFromProvidedSSHKey(keyInBytes);
Logger.getLogger(SSHAgent.class.getName()).log(Level.FINE, "Server sent challenge: {0}", Base64.toBase64String(challengeData));
Logger.getLogger(SSHAgent.class.getName()).log(Level.FINE, "Effective username: {0}", new String(userName));
Logger.getLogger(SSHAgent.class.getName()).log(Level.FINE, "Effective public key: {0}", Base64.toBase64String(keyInBytes));
代码示例来源:origin: Multibit-Legacy/multibit-hd
String base64Signature = Base64.toBase64String(signature.getSignature());
代码示例来源:origin: com.madgag.spongycastle/bcpkix-jdk15on
answer.setHeader("Authorization", "Basic " + Base64.toBase64String(userPass.getBytes()));
代码示例来源:origin: nebulasio/neb.java
String rawTransaction = Base64.toBase64String(rawData); // generate transaction raw data
代码示例来源:origin: HashEngineering/dashj
Base64.toBase64String(sig.getBytes()));
Base64.toBase64String(sig.getBytes()));
代码示例来源:origin: HashEngineering/dashj
message = strMessage.getBytes();
log.info("CMasternodeBroadcast::VerifySignature - sanitized strMessage: "+Utils.sanitizeString(strMessage)+", pubKeyCollateralAddress address: "+new Address(params, pubKeyCollateralAddress.getId()).toString()+", sig: %s\n" +
Base64.toBase64String(sig.getBytes()));
内容来源于网络,如有侵权,请联系作者删除!