All Downloads are FREE. Search and download functionalities are using the official Maven repository.

vite.api.utils.crypto.SignUtils Maven / Gradle / Ivy

The newest version!
package vite.api.utils.crypto;

import com.rfksystems.blake2b.Blake2b;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.util.encoders.Hex;
import vite.Wallet;

import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;

public class SignUtils {


    public static boolean verify(String address, String publicKeyHex, String signature) {


        boolean flag = Wallet.verify(Hex.decode(signature), Hex.decode(address.split("_")[1]), Hex.decode(publicKeyHex));

        return flag;
    }


    public static String sign(String address, String prikey) {

        Base64 base64 = new Base64();
        byte[] result = Wallet.sign(Hex.decode(address.split("_")[1]), Hex.decode(prikey));
        // boolean flag = Wallet.sign(Hex.decode(signature), Hex.decode(address.split("_")[1]), base64.decode(prikey));
        return Hex.toHexString(result);
    }


    public static byte[] Hash(int digestSize, byte[]... byteArrays) {
        requireNonNull(byteArrays, "Byte Arrays can't be null");

        Blake2b blake2b = new Blake2b(null, digestSize, null, null);

        Stream.of(byteArrays).forEach(byteArray -> blake2b.update(byteArray, 0, byteArray.length));

        byte[] output = new byte[digestSize];
        blake2b.digest(output, 0);
        return output;
    }


    public static byte[] Hash256(byte[] data) {

        return Hash(32, data);
    }


    public static byte[] Hash512(byte[] data) {

        return Hash(64, data);
    }

    public static byte[] gethash512to32(byte[] data) {

        byte[] result = Hash512(data);

        byte[] finalresult = new byte[32];

        System.arraycopy(result, 0, finalresult, 0, 32);

        return finalresult;
    }


    public static void main(String[] args) {
      /*  String hexData = "483d6f9dc40749ce7723461069febb697647b84c9903c33851747905d2c0b086";

        String signData = "24947dc637a753d13c40477623f55b21fff78fb5972bc0984822bff2bd7743a57a53b56cbbf2698e63ed9dbaea0bcddb111a262cde2373ce931f5f5b5f085b02";

        String pubkey = "f99e60917d5de7e347f5d2cbb325db8c0ec941f5ac9142b001e2049f971d7511";


        boolean flag = Wallet.verify(Hex.decode(signData),Hex.decode("483d6f9dc40749ce7723461069febb697647b84c9903c33851747905d2c0b086") , Hex.decode(pubkey));
        System.out.println(flag);*/


        String hexData = "3937a9e9de8aedb12e2b3a79895d7a23510d2e6181b3620f47d9f7d83df9c70d";

        String signData = "03ff0cb10bfdafa123ce1a072def4c2a812b3bd7e70b15c1b0a0b4c918a96e73628f8dc567af67e9a22fc0b59a4cb727a4d458e1fa4fb04586a8b716fd98cf07";

        String pubkey = "06d0550b965dc5af6bd235657a94693b2f0b464078062782e50c7377a5afbbc0";


        boolean flag = Wallet.verify(Hex.decode(signData),Hex.decode(hexData) , Hex.decode(pubkey));
        System.out.println(flag);

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy