public static string GenerateSecp256k1PublicKey(string privateKey, bool useCompression) { var Ecc = SecNamedCurves.GetByName("secp256k1"); var DomainParams = new ECDomainParameters(Ecc.Curve, Ecc.G, Ecc.N, Ecc.H); var bytes = Hex.Hex2Bytes(privateKey); BigInteger d = new BigInteger(bytes); ECPoint q = DomainParams.G.Multiply(d); q = q.Normalize(); var publicParams = new ECPublicKeyParameters(q, DomainParams); FpPoint fp = new FpPoint(Ecc.Curve, q.AffineXCoord, q.AffineYCoord); return(Hex.Bytes2Hex(fp.GetEncoded(useCompression))); }
public static byte[] XOR(string hex1, string hex2) { if (hex1.Length != hex2.Length) { throw new Exception("XOR cannot run on different length strings."); } byte[] bytes1 = Hex.Hex2Bytes(hex1); byte[] bytes2 = Hex.Hex2Bytes(hex2); for (int i = 0; i < bytes1.Length; i++) { bytes1[i] = (byte)(bytes1[i] ^ bytes2[i]); } return(bytes1); }
public static byte[] InsertAddressVersion(string pubkeyHash, string version) { var pubkeyHashBytes = Hex.Hex2Bytes(pubkeyHash); var versionBytes = Hex.Hex2Bytes(version); int space = (int)Math.Floor(20f / versionBytes.Length); byte[] extended = new byte[pubkeyHashBytes.Length + versionBytes.Length]; for (int i = 0, j = 0; i < pubkeyHashBytes.Length; i += space, j++) { var len = space; if (i + space >= pubkeyHashBytes.Length) { len = pubkeyHashBytes.Length - i; } Buffer.BlockCopy(versionBytes, j, extended, i + j, 1); Buffer.BlockCopy(pubkeyHashBytes, i, extended, i + j + 1, len); } return(extended); }