org.spongycastle.crypto.digests.SHA512Digest Java Examples

The following examples show how to use org.spongycastle.crypto.digests.SHA512Digest. 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: wallet_api.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private private_key derive_private_key(String strWifKey, int nSeqNumber) {
    String strData = strWifKey + " " + nSeqNumber;
    byte[] bytesBuffer = strData.getBytes();
    SHA512Digest digest = new SHA512Digest();
    digest.update(bytesBuffer, 0, bytesBuffer.length);

    byte[] out = new byte[64];
    digest.doFinal(out, 0);

    SHA256Digest digest256 = new SHA256Digest();
    byte[] outSeed = new byte[32];
    digest256.update(out, 0, out.length);
    digest.doFinal(outSeed, 0);

    return new private_key(outSeed);
}
 
Example #2
Source File: wallet_api.java    From bitshares_wallet with MIT License 6 votes vote down vote up
private private_key derive_private_key(String strWifKey, int nSeqNumber) {
    String strData = strWifKey + " " + nSeqNumber;
    byte[] bytesBuffer = strData.getBytes();
    SHA512Digest digest = new SHA512Digest();
    digest.update(bytesBuffer, 0, bytesBuffer.length);

    byte[] out = new byte[64];
    digest.doFinal(out, 0);

    SHA256Digest digest256 = new SHA256Digest();
    byte[] outSeed = new byte[32];
    digest256.update(out, 0, out.length);
    digest.doFinal(outSeed, 0);

    return new private_key(outSeed);
}
 
Example #3
Source File: sha512_object.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
public static sha512_object create_from_string(String strContent) {
    SHA512Digest digest = new SHA512Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #4
Source File: sha512_object.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
public static sha512_object create_from_byte_array(byte[] byteArray, int offset, int length) {
    SHA512Digest digest = new SHA512Digest();
    digest.update(byteArray, offset, length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #5
Source File: sha512_object.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public static sha512_object create_from_string(String strContent) {
    SHA512Digest digest = new SHA512Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #6
Source File: sha512_object.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public static sha512_object create_from_byte_array(byte[] byteArray, int offset, int length) {
    SHA512Digest digest = new SHA512Digest();
    digest.update(byteArray, offset, length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #7
Source File: sha512_object.java    From bitshares_wallet with MIT License 5 votes vote down vote up
public static sha512_object create_from_string(String strContent) {
    SHA512Digest digest = new SHA512Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #8
Source File: sha512_object.java    From bitshares_wallet with MIT License 5 votes vote down vote up
public static sha512_object create_from_byte_array(byte[] byteArray, int offset, int length) {
    SHA512Digest digest = new SHA512Digest();
    digest.update(byteArray, offset, length);

    byte[] byteHash = new byte[64];
    digest.doFinal(byteHash, 0);

    sha512_object sha512Object = new sha512_object();
    System.arraycopy(byteHash, 0, sha512Object.hash, 0, byteHash.length);

    return sha512Object;
}
 
Example #9
Source File: CryptoPrimitivesAndroid.java    From Clusion with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] generateHmac512(byte[] key, String msg) throws UnsupportedEncodingException {

		HMac hmac = new HMac(new SHA512Digest());
		byte[] result = new byte[hmac.getMacSize()];
		byte[] msgAry = msg.getBytes("UTF-8");
		hmac.init(new KeyParameter(key));
		hmac.reset();
		hmac.update(msgAry, 0, msgAry.length);
		hmac.doFinal(result, 0);
		return result;
	}
 
Example #10
Source File: HDUtils.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
static HMac createHmacSha512Digest(byte[] key) {
    SHA512Digest digest = new SHA512Digest();
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(key));
    return hMac;
}
 
Example #11
Source File: HDUtils.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
static HMac createHmacSha512Digest(byte[] key) {
    SHA512Digest digest = new SHA512Digest();
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(key));
    return hMac;
}
 
Example #12
Source File: HDUtils.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
static HMac createHmacSha512Digest(byte[] key) {
    SHA512Digest digest = new SHA512Digest();
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(key));
    return hMac;
}
 
Example #13
Source File: HDUtils.java    From bitherj with Apache License 2.0 4 votes vote down vote up
static HMac createHmacSha512Digest(byte[] key) {
    SHA512Digest digest = new SHA512Digest();
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(key));
    return hMac;
}
 
Example #14
Source File: MnemonicUtils.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 3 votes vote down vote up
/**
 * To create a binary seed from the mnemonic, we use the PBKDF2 function with a
 * mnemonic sentence (in UTF-8 NFKD) used as the password and the string "mnemonic"
 * + passphrase (again in UTF-8 NFKD) used as the salt. The iteration count is set
 * to 2048 and HMAC-SHA512 is used as the pseudo-random function. The length of the
 * derived key is 512 bits (= 64 bytes).
 *
 * @param mnemonic The input mnemonic which should be 128-160 bits in length containing
 *                 only valid words
 * @param passphrase The passphrase which will be used as part of salt for PBKDF2
 *                   function
 * @return Byte array representation of the generated seed
 */
public static byte[] generateSeed(String mnemonic, String passphrase) {
    validateMnemonic(mnemonic);
    passphrase = passphrase == null ? "" : passphrase;

    String salt = String.format("mnemonic%s", passphrase);
    PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA512Digest());
    gen.init(mnemonic.getBytes(Charset.forName("UTF-8")), salt.getBytes(Charset.forName("UTF-8")), SEED_ITERATIONS);

    return ((KeyParameter) gen.generateDerivedParameters(SEED_KEY_SIZE)).getKey();
}