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


Java Base64.decode方法代码示例

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


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

示例1: signatureToKeyBytes

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * 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)));
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:31,代码来源:ECKey.java

示例2: signatureToKeyBytes

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * 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)));
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:31,代码来源:ECKey.java

示例3: signatureToKeyBytes

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * 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)));
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:31,代码来源:ECKey.java

示例4: decrypt

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:15,代码来源:Aes.java

示例5: readIvFromFileOrGenerateNew

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
private byte[] readIvFromFileOrGenerateNew() {
    final String encoded = null;// = this.preferences.getString(IV, null);
    if (encoded == null) {
        return generateAndSaveIv();
    }
    return Base64.decode(encoded);
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:8,代码来源:Aes.java

示例6: signatureToKey

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * 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 ECKey signatureToKey(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);
    }
    int header = signatureEncoded[0] & 0xFF;
    // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
    //                  0x1D = second key with even y, 0x1E = second key with odd y
    if (header < 27 || header > 34) {
        throw new SignatureException("Header byte out of range: " + header);
    }
    BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
    BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
    ECDSASignature sig = new ECDSASignature(r, s);
    boolean compressed = false;
    if (header >= 31) {
        compressed = true;
        header -= 4;
    }
    int recId = header - 27;
    ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed);
    if (key == null) {
        throw new SignatureException("Could not recover public key from signature");
    }
    return key;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:45,代码来源:ECKey.java

示例7: signedMessageToKey

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * Given an arbitrary piece of text and a Bitcoin-format 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. These sorts of signatures are compatible with the Bitcoin-Qt/bitcoind
 * format generated by signmessage/verifymessage RPCs and GUI menu options. They are intended for humans to verify
 * their communications with each other, hence the base64 format and the fact that the input is text.
 *
 * @param message Some piece of human readable text.
 * @param signatureBase64 The Bitcoin-format message signature in base64
 * @throws SignatureException If the public key could not be recovered or if there was a signature format error.
 */
public static ECKey signedMessageToKey(String message, 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);
    int header = signatureEncoded[0] & 0xFF;
    // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
    //                  0x1D = second key with even y, 0x1E = second key with odd y
    if (header < 27 || header > 34)
        throw new SignatureException("Header byte out of range: " + header);
    BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
    BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
    ECDSASignature sig = new ECDSASignature(r, s);
    byte[] messageBytes = Utils.formatMessageForSigning(message);
    // Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever
    // JSON-SPIRIT hands back. Assume UTF-8 for now.
    Sha256Hash messageHash = Sha256Hash.twiceOf(messageBytes);
    boolean compressed = false;
    if (header >= 31) {
        compressed = true;
        header -= 4;
    }
    int recId = header - 27;
    ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed);
    if (key == null)
        throw new SignatureException("Could not recover public key from signature");
    return key;
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:46,代码来源:ECKey.java

示例8: signedMessageToKey

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * Given an arbitrary piece of text and a Bitcoin-format 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. These sorts of signatures are compatible with the Bitcoin-Qt/bitcoind
 * format generated by signmessage/verifymessage RPCs and GUI menu options. They are intended for humans to verify
 * their communications with each other, hence the base64 format and the fact that the input is text.
 *
 * @param message Some piece of human readable text.
 * @param signatureBase64 The Bitcoin-format message signature in base64
 * @throws SignatureException If the public key could not be recovered or if there was a signature format error.
 */
public static BtcECKey signedMessageToKey(String message, 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);
    int header = signatureEncoded[0] & 0xFF;
    // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
    //                  0x1D = second key with even y, 0x1E = second key with odd y
    if (header < 27 || header > 34)
        throw new SignatureException("Header byte out of range: " + header);
    BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
    BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
    ECDSASignature sig = new ECDSASignature(r, s);
    byte[] messageBytes = Utils.formatMessageForSigning(message);
    // Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever
    // JSON-SPIRIT hands back. Assume UTF-8 for now.
    Sha256Hash messageHash = Sha256Hash.twiceOf(messageBytes);
    boolean compressed = false;
    if (header >= 31) {
        compressed = true;
        header -= 4;
    }
    int recId = header - 27;
    BtcECKey key = BtcECKey.recoverFromSignature(recId, sig, messageHash, compressed);
    if (key == null)
        throw new SignatureException("Could not recover public key from signature");
    return key;
}
 
开发者ID:rsksmart,项目名称:bitcoinj-thin,代码行数:46,代码来源:BtcECKey.java

示例9: signedMessageToKey

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * Given an arbitrary piece of text and a NithPoints-format 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. These sorts of signatures are compatible with the NithPoints-Qt/NithPointsd
 * format generated by signmessage/verifymessage RPCs and GUI menu options. They are intended for humans to verify
 * their communications with each other, hence the base64 format and the fact that the input is text.
 *
 * @param message Some piece of human readable text.
 * @param signatureBase64 The NithPoints-format message signature in base64
 * @throws SignatureException If the public key could not be recovered or if there was a signature format error.
 */
public static ECKey signedMessageToKey(String message, 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);
    int header = signatureEncoded[0] & 0xFF;
    // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
    //                  0x1D = second key with even y, 0x1E = second key with odd y
    if (header < 27 || header > 34)
        throw new SignatureException("Header byte out of range: " + header);
    BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
    BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
    ECDSASignature sig = new ECDSASignature(r, s);
    byte[] messageBytes = Utils.formatMessageForSigning(message);
    // Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever
    // JSON-SPIRIT hands back. Assume UTF-8 for now.
    Sha256Hash messageHash = Sha256Hash.createDouble(messageBytes);
    boolean compressed = false;
    if (header >= 31) {
        compressed = true;
        header -= 4;
    }
    int recId = header - 27;
    ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed);
    if (key == null)
        throw new SignatureException("Could not recover public key from signature");
    return key;
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:46,代码来源:ECKey.java

示例10: getEncryptedKeyFromBase64Text

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static SymmetricKeyEncrypted getEncryptedKeyFromBase64Text(String text) throws Base64DecodingException {
    try {
        byte[] data = Base64.decode(text);
        return getEncryptedKeyFromTransferBytes(data);
    }
    catch (DecoderException ex) {
        throw new Base64DecodingException(ex);
    }
}
 
开发者ID:oversecio,项目名称:oversec_crypto,代码行数:10,代码来源:OversecKeystore2.java

示例11: getPlainKeyFromBase64Text

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
public static SymmetricKeyPlain getPlainKeyFromBase64Text(String text) throws Base64DecodingException {
    try {
        byte[] data = Base64.decode(text);
        return getPlainKeyFromTransferBytes(data);
    }
    catch (DecoderException ex) {
        throw new Base64DecodingException(ex);
    }
}
 
开发者ID:oversecio,项目名称:oversec_crypto,代码行数:10,代码来源:OversecKeystore2.java

示例12: loadObject

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
private PemObject loadObject(String type)
    throws IOException
{
    String          line;
    String          endMarker = END + type;
    StringBuilder buf = new StringBuilder();
    List            headers = new ArrayList();

    while ((line = readLine()) != null)
    {
        if (line.indexOf(":") >= 0)
        {
            int index = line.indexOf(':');
            String hdr = line.substring(0, index);
            String value = line.substring(index + 1).trim();

            headers.add(new PemHeader(hdr, value));

            continue;
        }

        if (line.indexOf(endMarker) != -1)
        {
            break;
        }
        
        buf.append(line.trim());
    }

    if (line == null)
    {
        throw new IOException(endMarker + " not found");
    }

    return new PemObject(type, headers, Base64.decode(buf.toString()));
}
 
开发者ID:MaxSmile,项目名称:EasyVPN-Free,代码行数:37,代码来源:PemReader.java

示例13: signatureToKey

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
/**
 * 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 ECKey signatureToKey(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);
    int header = signatureEncoded[0] & 0xFF;
    // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
    // 0x1D = second key with even y, 0x1E = second key with odd y
    if (header < 27 || header > 34)
        throw new SignatureException("Header byte out of range: " + header);
    BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
    BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
    ECDSASignature sig = new ECDSASignature(r, s);
    boolean compressed = false;
    if (header >= 31) {
        compressed = true;
        header -= 4;
    }
    int recId = header - 27;
    ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed);
    if (key == null)
        throw new SignatureException("Could not recover public key from signature");
    return key;
}
 
开发者ID:cegeka,项目名称:tether,代码行数:48,代码来源:ECKey.java

示例14: testTrezorSSHKeyConversion

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Test
public void testTrezorSSHKeyConversion() throws Exception {
    ECPublicKey publicKeyFromBytes = IdentityUtils.decodeNISTP256PublicKeyFromBytes(pubKeyTrezor);
    String decompressSSHKeyFromNistp256 = IdentityUtils.serializeSSHKeyFromNistp256(publicKeyFromBytes);
    byte[] sshKey = Base64.decode(decompressSSHKeyFromNistp256);

    Assert.assertTrue(Arrays.equals(sshKey, pubKeySSHTrezor));
}
 
开发者ID:martin-lizner,项目名称:trezor-ssh-agent,代码行数:9,代码来源:ECDSATest.java

示例15: testKeepKeySSHKeyConversion

import org.spongycastle.util.encoders.Base64; //导入方法依赖的package包/类
@Test
public void testKeepKeySSHKeyConversion() throws Exception {
    ECPublicKey publicKeyFromBytes = IdentityUtils.decodeNISTP256PublicKeyFromBytes(pubKeyKeepKey);
    String decompressSSHKeyFromNistp256 = IdentityUtils.serializeSSHKeyFromNistp256(publicKeyFromBytes);
    byte[] sshKey = Base64.decode(decompressSSHKeyFromNistp256);

    Assert.assertTrue(Arrays.equals(sshKey, pubKeySSHKeepKey));
}
 
开发者ID:martin-lizner,项目名称:trezor-ssh-agent,代码行数:9,代码来源:ECDSATest.java


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