Java Code Examples for org.spongycastle.crypto.digests.SHA256Digest#update()

The following examples show how to use org.spongycastle.crypto.digests.SHA256Digest#update() . 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: types.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String toString() {
    byte[] data = new byte[key_data.length + 1 + 4];
    data[0] = (byte) 0x80;
    System.arraycopy(key_data, 0, data, 1, key_data.length);

    SHA256Digest digest = new SHA256Digest();
    digest.update(data, 0, key_data.length + 1);
    byte[] out = new byte[32];
    digest.doFinal(out, 0);

    digest.update(out, 0, out.length);
    digest.doFinal(out, 0);

    System.arraycopy(out, 0, data, key_data.length + 1, 4);
    return Base58.encode(data);
}
 
Example 2
Source File: types.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String toString() {
    byte[] data = new byte[key_data.length + 1 + 4];
    data[0] = (byte)0x80;
    System.arraycopy(key_data, 0, data, 1, key_data.length);

    SHA256Digest digest = new SHA256Digest();
    digest.update(data, 0, key_data.length + 1);
    byte[] out = new byte[32];
    digest.doFinal(out, 0);

    digest.update(out, 0, out.length);
    digest.doFinal(out, 0);

    System.arraycopy(out, 0, data, key_data.length + 1, 4);
    return Base58.encode(data);
}
 
Example 3
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 4
Source File: types.java    From bitshares_wallet with MIT License 6 votes vote down vote up
@Override
public String toString() {
    byte[] data = new byte[key_data.length + 1 + 4];
    data[0] = (byte)0x80;
    System.arraycopy(key_data, 0, data, 1, key_data.length);

    SHA256Digest digest = new SHA256Digest();
    digest.update(data, 0, key_data.length + 1);
    byte[] out = new byte[32];
    digest.doFinal(out, 0);

    digest.update(out, 0, out.length);
    digest.doFinal(out, 0);

    System.arraycopy(out, 0, data, key_data.length + 1, 4);
    return Base58.encode(data);
}
 
Example 5
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 6
Source File: sha256_object.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
public static sha256_object create_from_string(String strContent) {
    SHA256Digest digest = new SHA256Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

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

    sha256_object sha256Object = new sha256_object();
    System.arraycopy(byteHash, 0, sha256Object.hash, 0, byteHash.length);

    return sha256Object;
}
 
Example 7
Source File: types.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
public private_key_type(String strBase58) throws KeyInvalideException, AddressFormatException {
    byte wif_bytes[] = Base58.decode(strBase58);

    if (wif_bytes.length < key_data.length) {
        throw new KeyInvalideException("Private key is not valid");
    }
    System.arraycopy(wif_bytes, 1, key_data, 0, key_data.length);
    SHA256Digest digest = new SHA256Digest();
    digest.update(wif_bytes, 0, wif_bytes.length - 4);
    byte[] hashCheck = new byte[32];
    digest.doFinal(hashCheck, 0);

    byte[] hashCheck2 = new byte[32];
    digest.update(hashCheck, 0, hashCheck.length);
    digest.doFinal(hashCheck2, 0);

    byte check[] = new byte[4];
    System.arraycopy(wif_bytes, wif_bytes.length - check.length, check, 0, check.length);

    byte[] check1 = new byte[4];
    byte[] check2 = new byte[4];
    System.arraycopy(hashCheck, 0, check1, 0, check1.length);
    System.arraycopy(hashCheck2, 0, check2, 0, check2.length);
    if (!Arrays.equals(check1, check) && !Arrays.equals(check2, check)) {
        throw new KeyInvalideException("Private key is not valid");
    }
}
 
Example 8
Source File: sha256_object.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public static sha256_object create_from_string(String strContent) {
    SHA256Digest digest = new SHA256Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

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

    sha256_object sha256Object = new sha256_object();
    System.arraycopy(byteHash, 0, sha256Object.hash, 0, byteHash.length);

    return sha256Object;
}
 
Example 9
Source File: types.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public private_key_type(String strBase58) {
    byte wif_bytes[] = Base58.decode(strBase58);
    if (wif_bytes.length < 5) {
        throw new RuntimeException("Private key is not valid");
    }

    System.arraycopy(wif_bytes, 1, key_data, 0, key_data.length);

    SHA256Digest digest = new SHA256Digest();
    digest.update(wif_bytes, 0, wif_bytes.length - 4);
    byte[] hashCheck = new byte[32];
    digest.doFinal(hashCheck, 0);

    byte[] hashCheck2 = new byte[32];
    digest.update(hashCheck, 0, hashCheck.length);
    digest.doFinal(hashCheck2, 0);

    byte check[] = new byte[4];
    System.arraycopy(wif_bytes, wif_bytes.length - check.length, check, 0, check.length);

    byte[] check1 = new byte[4];
    byte[] check2 = new byte[4];
    System.arraycopy(hashCheck, 0, check1, 0, check1.length);
    System.arraycopy(hashCheck2, 0, check2, 0, check2.length);

    if (Arrays.equals(check1, check) == false &&
            Arrays.equals(check2, check) == false) {
        throw new RuntimeException("Private key is not valid");
    }
}
 
Example 10
Source File: sha256_object.java    From bitshares_wallet with MIT License 5 votes vote down vote up
public static sha256_object create_from_string(String strContent) {
    SHA256Digest digest = new SHA256Digest();
    byte[] bytePassword = strContent.getBytes();
    digest.update(bytePassword, 0, bytePassword.length);

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

    sha256_object sha256Object = new sha256_object();
    System.arraycopy(byteHash, 0, sha256Object.hash, 0, byteHash.length);

    return sha256Object;
}
 
Example 11
Source File: types.java    From bitshares_wallet with MIT License 5 votes vote down vote up
public private_key_type(String strBase58) {
    byte wif_bytes[] = Base58.decode(strBase58);
    if (wif_bytes.length < 5) {
        throw new RuntimeException("Private key is not valid");
    }

    System.arraycopy(wif_bytes, 1, key_data, 0, key_data.length);

    SHA256Digest digest = new SHA256Digest();
    digest.update(wif_bytes, 0, wif_bytes.length - 4);
    byte[] hashCheck = new byte[32];
    digest.doFinal(hashCheck, 0);

    byte[] hashCheck2 = new byte[32];
    digest.update(hashCheck, 0, hashCheck.length);
    digest.doFinal(hashCheck2, 0);

    byte check[] = new byte[4];
    System.arraycopy(wif_bytes, wif_bytes.length - check.length, check, 0, check.length);

    byte[] check1 = new byte[4];
    byte[] check2 = new byte[4];
    System.arraycopy(hashCheck, 0, check1, 0, check1.length);
    System.arraycopy(hashCheck2, 0, check2, 0, check2.length);

    if (Arrays.equals(check1, check) == false &&
            Arrays.equals(check2, check) == false) {
        throw new RuntimeException("Private key is not valid");
    }
}