Exemple #1
0
 public static SqlString getDerivedKey(SqlString sharedSecret)
 {
     byte[] ssBytes = Encoding.ASCII.GetBytes(sharedSecret.ToString());
     try
     {
         byte[] dk = BCFunctions.DeriveSymmetricKeyFromSharedSecret(ssBytes);
         return(Convert.ToBase64String(dk));
     }
     catch { return(""); }
 }
Exemple #2
0
        public static SqlString getSharedSecret(SqlString keySize, SqlString PrivateKey, SqlString PublicKey)
        {
            //X9ECParameters ecP = NistNamedCurves.GetByName("P-" + keySize.ToString());
            //var c = (FpCurve)ecP.Curve;
            //var eCDomainParameters = new ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed());

            BigInteger dA = new BigInteger(PrivateKey.ToString(), 10);

            //ECPrivateKeyParameters keyParametersA = new ECPrivateKeyParameters(dA, eCDomainParameters);
            byte[] pkBytes = dA.ToByteArray();

            byte[] pbBytes = Convert.FromBase64String(PublicKey.ToString());

            byte[] ss = BCFunctions.getSharedSecret(pkBytes, pbBytes);
            return(Convert.ToBase64String(ss));
        }
Exemple #3
0
        public static SqlString getSignature(SqlString keySize, SqlString PrivateKey, SqlString Message)
        {
            X9ECParameters     ecParams         = NistNamedCurves.GetByName("P-" + keySize.ToString());
            ECDomainParameters domainParameters = new ECDomainParameters(ecParams.Curve, ecParams.G, ecParams.N, ecParams.H, ecParams.GetSeed());
            var     G     = ecParams.G;
            ECCurve curve = ecParams.Curve;

            //private Key
            BigInteger             d             = new BigInteger(PrivateKey.ToString(), 10);
            ECPrivateKeyParameters keyParameters = new ECPrivateKeyParameters(d, domainParameters);

            //public key
            ECPoint q = domainParameters.G.Multiply(d);
            ECPublicKeyParameters pubkeyParam = new ECPublicKeyParameters(q, domainParameters);

            string s            = Message.ToString();
            var    signature    = BCFunctions.GetSignature(s, keyParameters);
            var    signedString = Convert.ToBase64String(signature);
            var    txtSignature = signedString;

            return(txtSignature);
        }
Exemple #4
0
        public static SqlXml generateKeys(SqlString keySize, SqlString network)
        {
            AsymmetricCipherKeyPair key = BCFunctions.GenerateKeys(Convert.ToInt16(keySize.ToString()));

            ECPublicKeyParameters  publicKeyParam  = (ECPublicKeyParameters)key.Public;
            ECPrivateKeyParameters privateKeyParam = (ECPrivateKeyParameters)key.Private;

            var        privateKey = privateKeyParam.D.ToString();
            BigInteger d          = new BigInteger(privateKey, 10);

            var publicKey = BCFunctions.RetrievePublicKey(keySize.ToString(), d);

            var addressText = "0x" + BitConverter.ToString(BCFunctions.Hash(publicKey, network.ToString())).Replace("-", "");

            var         r      = "<sqroot><D>" + privateKey + "</D><Q>" + publicKey + "</Q><A>" + addressText + "</A></sqroot>";
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(r);
            XmlNodeReader xnr = new XmlNodeReader(xmlDoc);
            SqlXml        rx  = new SqlXml(xnr);

            return(rx);
        }
Exemple #5
0
        public static SqlString retrievePublicKey(SqlString keySize, SqlString privateKey)
        {
            BigInteger DString = new BigInteger(privateKey.ToString(), 10);

            return(BCFunctions.RetrievePublicKey(keySize.ToString(), DString));
        }