本文整理了Java中org.spongycastle.util.encoders.Base64.decode()
方法的一些代码示例,展示了Base64.decode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.decode()
方法的具体详情如下:
包路径:org.spongycastle.util.encoders.Base64
类名称:Base64
方法名:decode
[英]decode the base 64 encoded String data - whitespace will be ignored.
[中]解码base64编码的字符串数据-空白将被忽略。
代码示例来源:origin: ethereum/ethereumj
/**
* Given a piece of text and a message signature encoded in base64, returns an ECKey
* containing the public key that was used to sign it. This can then be compared to the expected public key to
* determine if the signature was correct.
*
* @param messageHash a piece of human readable text that was signed
* @param signatureBase64 The Ethereum-format message signature in base64
*
* @return -
* @throws SignatureException If the public key could not be recovered or if there was a signature format error.
*/
public static byte[] signatureToKeyBytes(byte[] messageHash, String signatureBase64) throws SignatureException {
byte[] signatureEncoded;
try {
signatureEncoded = Base64.decode(signatureBase64);
} catch (RuntimeException e) {
// This is what you get back from Bouncy Castle if base64 doesn't decode :(
throw new SignatureException("Could not decode base64", e);
}
// Parse the signature bytes into r/s and the selector value.
if (signatureEncoded.length < 65)
throw new SignatureException("Signature truncated, expected 65 bytes and got " + signatureEncoded.length);
return signatureToKeyBytes(
messageHash,
ECDSASignature.fromComponents(
Arrays.copyOfRange(signatureEncoded, 1, 33),
Arrays.copyOfRange(signatureEncoded, 33, 65),
(byte) (signatureEncoded[0] & 0xFF)));
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/**
* <p>base64Decode.</p>
*
* @param string a {@link java.lang.String} object.
* @return an array of byte.
*/
public static byte[] base64Decode(String string) {
return Base64.decode(string);
}
代码示例来源:origin: nebulasio/neb.java
public static byte[] Base64ToBytes(String data) {
return Base64.decode(data);
}
代码示例来源:origin: cternes/openkeepass
@Override
public byte[] read(String value) throws Exception {
return Base64.decode(value.getBytes());
}
代码示例来源:origin: cternes/openkeepass
@Override
public UUID read(String value) throws Exception {
if(value == null) {
return null;
}
return ByteUtils.bytesToUUID(Base64.decode(value.getBytes()));
}
代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar
private boolean isValidToken(String token) {
try {
String tokenParamsJsonB64 = token.split("\\.")[1] + "=";
String tokenParamsJson = new String(Base64.decode(tokenParamsJsonB64.getBytes("utf-8")));
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
JsonNode rootNode = mapper.readTree(tokenParamsJson);
long expDate = rootNode.get("exp").asLong() * 1000;
long now = System.currentTimeMillis();
return now < expDate;
} catch (Exception e) {
return false;
}
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/** {@inheritDoc} */
@Override
public byte[] base64Decode(String string) {
return Base64.decode(StringUtils.removeWhitespace(string));
}
代码示例来源:origin: cternes/openkeepass
@Override
public KeyFileBytes readKeyFile(byte[] keyFile) {
byte[] protectedBuffer = keyFile;
int length = keyFile.length;
if (length == 64) {
protectedBuffer = Base64.decode(keyFile);
}
return new KeyFileBytes(true, protectedBuffer);
}
代码示例来源:origin: OPCFoundation/UA-Java-Legacy
/** {@inheritDoc} */
@Override
public byte[] base64Decode(String string) {
return Base64.decode(StringUtils.removeWhitespace(string));
}
代码示例来源:origin: CoinbaseWallet/toshi-headless-client
private byte[] readIvFromFileOrGenerateNew() {
final String encoded = null;// = this.preferences.getString(IV, null);
if (encoded == null) {
return generateAndSaveIv();
}
return Base64.decode(encoded);
}
代码示例来源:origin: Coinomi/coinomi-android
static String decrypt(long key, String fullMessage) throws DataFormatException {
byte[] bytes = decryptBytes(key, Base64.decode(fullMessage));
return new String(bytes);
}
代码示例来源:origin: openwalletGH/openwallet-android
static String decrypt(long key, String fullMessage) throws DataFormatException {
byte[] bytes = decryptBytes(key, Base64.decode(fullMessage));
return new String(bytes);
}
代码示例来源:origin: CoinbaseWallet/toshi-headless-client
public String decrypt(final String cryptedText, final String password) {
if (this.cipher == null) {
initWithPassword(password);
}
try {
cipher.init(Cipher.DECRYPT_MODE, key, spec);
final byte[] bytes = Base64.decode(cryptedText);
final byte[] decrypted = cipher.doFinal(bytes);
return new String(decrypted, "UTF-8");
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: QuincySx/BlockchainWallet-Crypto
public static String decode(String input) {
return Strings.fromByteArray(org.spongycastle.util.encoders.Base64.decode(input));
}
代码示例来源:origin: cternes/openkeepass
@Override
public String decrypt(String protectedString) {
if (protectedString == null) {
throw new IllegalArgumentException("ProtectedString must not be null");
}
byte[] protectedBuffer = Base64.decode(protectedString.getBytes());
byte[] plainText = new byte[protectedBuffer.length];
try {
salsa20Engine.processBytes(protectedBuffer, 0, protectedBuffer.length, plainText, 0);
return new String(plainText, ENCODING);
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(MSG_UNKNOWN_UTF8_ENCODING, e);
}
}
代码示例来源:origin: cternes/openkeepass
private byte[] getBytesFromKeyFile(KeyFile keyFile) {
try {
return Base64.decode(keyFile.getKey().getData().getBytes(UTF_8));
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(MSG_UTF8_NOT_SUPPORTED, e);
}
}
}
代码示例来源:origin: tronprotocol/wallet-cli
public static byte[] signatureToKeyBytes(byte[] messageHash, String
signatureBase64) throws SignatureException {
byte[] signatureEncoded;
try {
signatureEncoded = Base64.decode(signatureBase64);
} catch (RuntimeException e) {
// This is what you getData back from Bouncy Castle if base64 doesn't
// decode :(
throw new SignatureException("Could not decode base64", e);
}
// Parse the signature bytes into r/s and the selector value.
if (signatureEncoded.length < 65) {
throw new SignatureException("Signature truncated, expected 65 " +
"bytes and got " + signatureEncoded.length);
}
return signatureToKeyBytes(
messageHash,
ECDSASignature.fromComponents(
Arrays.copyOfRange(signatureEncoded, 1, 33),
Arrays.copyOfRange(signatureEncoded, 33, 65),
(byte) (signatureEncoded[0] & 0xFF)));
}
代码示例来源:origin: UniversaBlockchain/universa
public Binder extractParams(BasicHTTPService.Request request) {
Binder rp = request.getParams();
String sparams = rp.getString("requestData64", null);
if (sparams != null) {
byte [] x = Base64.decode(sparams);
return Boss.unpack(x);
} else {
BasicHTTPService.FileUpload rd = (BasicHTTPService.FileUpload) rp.get("requestData");
if (rd != null) {
byte[] data = rd.getBytes();
return Boss.unpack(data);
}
}
return Binder.EMPTY;
}
代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar
/**
* Get metadata entry
*/
private String getMetadataEntry(String address, boolean isEncrypted) throws MetadataException,
IOException,
InvalidCipherTextException {
Call<MetadataResponse> response = getApiInstance().getMetadata(address);
Response<MetadataResponse> exe = response.execute();
if (exe.isSuccessful()) {
if (isEncrypted) {
return AESUtil.decryptWithKey(encryptionKey, exe.body().getPayload());
} else {
return new String(Base64.decode(exe.body().getPayload()));
}
} else {
if (exe.code() == 404) {
return null;
} else {
throw new MetadataException(exe.code() + " " + exe.message());
}
}
}
代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar
public void fetchMagic() throws IOException, MetadataException {
Call<MetadataResponse> response = getApiInstance().getMetadata(address);
Response<MetadataResponse> exe = response.execute();
if (exe.isSuccessful()) {
MetadataResponse body = exe.body();
byte[] encryptedPayloadBytes = Base64.decode(exe.body().getPayload().getBytes("utf-8"));
if (body.getPrevMagicHash() != null) {
byte[] prevMagicBytes = Hex.decode(body.getPrevMagicHash());
magicHash = MetadataUtil.magic(encryptedPayloadBytes, prevMagicBytes);
} else {
magicHash = MetadataUtil.magic(encryptedPayloadBytes, null);
}
} else {
if (exe.code() == 404) {
magicHash = null;
} else {
throw new MetadataException(exe.code() + " " + exe.message());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!