/** * Create a mnemonic from the word list given the entropy. * * @param entropy 128-256 bits of entropy, number of bits must also be divisible by 32 * @param target Where to write the mnemonic to */ public void createMnemonic( final byte[] entropy, final Target target) { final int[] wordIndexes = wordIndexes(entropy); try { createMnemonic(wordIndexes, target); } finally { Arrays.fill(wordIndexes, 0); } }
public static String generateMnemonicCodesStr(){ final StringBuilder sb = new StringBuilder(); byte[] entropy = new byte[Words.TWELVE.byteLength()]; new SecureRandom().nextBytes(entropy); new MnemonicGenerator(English.INSTANCE).createMnemonic(entropy, new MnemonicGenerator.Target() { @Override public void append(CharSequence string) { sb.append(string); } }); new SecureRandom().nextBytes(entropy); return sb.toString(); }
/** * Create a mnemonic from the word list given the entropy. * * @param entropy 128-256 bits of entropy, number of bits must also be divisible by 32 * @param target Where to write the mnemonic to */ public void createMnemonic( final byte[] entropy, final Target target) { final int[] wordIndexes = wordIndexes(entropy); try { createMnemonic(wordIndexes, target); } finally { Arrays.fill(wordIndexes, 0); } }
public static String generateMnemonicCodesStr(){ final StringBuilder sb = new StringBuilder(); byte[] entropy = new byte[Words.TWELVE.byteLength()]; new SecureRandom().nextBytes(entropy); new MnemonicGenerator(English.INSTANCE).createMnemonic(entropy, new MnemonicGenerator.Target() { @Override public void append(CharSequence string) { sb.append(string); } }); new SecureRandom().nextBytes(entropy); return sb.toString(); }
/** * Create a mnemonic from the word list given the entropy. * * @param entropyHex 128-256 bits of hex entropy, number of bits must also be divisible by 32 * @param target Where to write the mnemonic to */ public void createMnemonic( final CharSequence entropyHex, final Target target) { final int length = entropyHex.length(); if (length % 2 != 0) throw new RuntimeException("Length of hex chars must be divisible by 2"); final byte[] entropy = new byte[length / 2]; try { for (int i = 0, j = 0; i < length; i += 2, j++) { entropy[j] = (byte) (parseHex(entropyHex.charAt(i)) << 4 | parseHex(entropyHex.charAt(i + 1))); } createMnemonic(entropy, target); } finally { Arrays.fill(entropy, (byte) 0); } }
/** * Create a mnemonic from the word list given the entropy. * * @param entropyHex 128-256 bits of hex entropy, number of bits must also be divisible by 32 * @param target Where to write the mnemonic to */ public void createMnemonic( final CharSequence entropyHex, final Target target) { final int length = entropyHex.length(); if (length % 2 == 1) throw new RuntimeException("Length of hex chars must be divisible by 2"); final byte[] entropy = new byte[length / 2]; try { for (int i = 0, j = 0; i < length; i += 2, j++) { entropy[j] = (byte) (parseHex(entropyHex.charAt(i)) << 4 | parseHex(entropyHex.charAt(i + 1))); } createMnemonic(entropy, target); } finally { Arrays.fill(entropy, (byte) 0); } }
private static String createMnemonic(byte[] f, WordList wordList) { final StringBuilder sb = new StringBuilder(); new MnemonicGenerator(wordList) .createMnemonic(f, sb::append); return sb.toString(); } }
private static String createMnemonic(String f, WordList wordList) { final StringBuilder sb = new StringBuilder(); new MnemonicGenerator(wordList) .createMnemonic(f, sb::append); return sb.toString(); }
private static String createMnemonic(byte[] f, WordList wordList) { final StringBuilder sb = new StringBuilder(); new MnemonicGenerator(wordList) .createMnemonic(f, sb::append); return sb.toString(); }
@Test public void forFinallyCodeCoverage_createMnemonicWhenTargetThrowsException() throws Exception { assertThatThrownBy( () -> new MnemonicGenerator(English.INSTANCE) .createMnemonic(repeatString(32, "f"), (s) -> { throw new OutOfMemoryError(); })) .isInstanceOf(OutOfMemoryError.class); }