Java Code Examples for org.bitcoinj.core.Sha256Hash#newDigest()

The following examples show how to use org.bitcoinj.core.Sha256Hash#newDigest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MnemonicCode.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates an MnemonicCode object, initializing with words read from the supplied input stream.  If a wordListDigest
 * is supplied the digest of the words will be checked.
 */
public MnemonicCode(InputStream wordstream, String wordListDigest) throws IOException, IllegalArgumentException {
    BufferedReader br = new BufferedReader(new InputStreamReader(wordstream, StandardCharsets.UTF_8));
    this.wordList = new ArrayList<>(2048);
    MessageDigest md = Sha256Hash.newDigest();
    String word;
    while ((word = br.readLine()) != null) {
        md.update(word.getBytes());
        this.wordList.add(word);
    }
    br.close();

    if (this.wordList.size() != 2048)
        throw new IllegalArgumentException("input stream did not contain 2048 words");

    // If a wordListDigest is supplied check to make sure it matches.
    if (wordListDigest != null) {
        byte[] digest = md.digest();
        String hexdigest = HEX.encode(digest);
        if (!hexdigest.equals(wordListDigest))
            throw new IllegalArgumentException("wordlist digest mismatch");
    }
}
 
Example 2
Source File: MnemonicCode.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
private void initializeFromWords(ArrayList<String> wordList, String wordListDigest) throws IllegalArgumentException {
    if (wordList.size() != 2048)
        throw new IllegalArgumentException("input wordlist did not contain 2048 words");

    this.wordList = wordList;

    // If a wordListDigest is supplied check to make sure it matches.
    if (wordListDigest != null) {
        MessageDigest md = Sha256Hash.newDigest();
        for (String word : wordList)
            md.update(word.getBytes());

        byte[] digest = md.digest();
        String hexdigest = HEX.encode(digest);
        if (!hexdigest.equals(wordListDigest))
            throw new IllegalArgumentException("wordlist digest mismatch");
    }
}
 
Example 3
Source File: MnemonicCode.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
private void initializeFromWords(ArrayList<String> wordList, String wordListDigest) throws IllegalArgumentException {
    if (wordList.size() != 2048)
        throw new IllegalArgumentException("input wordlist did not contain 2048 words");

    this.wordList = wordList;

    // If a wordListDigest is supplied check to make sure it matches.
    if (wordListDigest != null) {
        MessageDigest md = Sha256Hash.newDigest();
        for (String word : wordList)
            md.update(word.getBytes());

        byte[] digest = md.digest();
        String hexdigest = HEX.encode(digest);
        if (!hexdigest.equals(wordListDigest))
            throw new IllegalArgumentException("wordlist digest mismatch");
    }
}