示例#1
0
        /**
         * return a X9ECParameters object representing the passed in named
         * curve. The routine returns null if the curve is not present.
         *
         * @param name the name of the curve requested
         * @return an X9ECParameters object or null if the curve is not available.
         */
        public static X9ECParameters GetByName(string name)
        {
            X9ECParameters ecP = X962NamedCurves.GetByName(name);

            if (ecP == null)
            {
                ecP = SecNamedCurves.GetByName(name);
            }

            if (ecP == null)
            {
                ecP = NistNamedCurves.GetByName(name);
            }

            if (ecP == null)
            {
                ecP = TeleTrusTNamedCurves.GetByName(name);
            }

            if (ecP == null)
            {
                ecP = AnssiNamedCurves.GetByName(name);
            }

            return(ecP);
        }
示例#2
0
        static void ECCTest()
        {
            string curveName = "P-521";
            var    ecP1      = AnssiNamedCurves.GetByName("FRP256v1");
            var    ecP21     = TeleTrusTNamedCurves.GetByName("brainpoolp512t1");
            var    ecP       = NistNamedCurves.GetByName(curveName);
            var    random    = new SecureRandom();

            var eCDomainParameters = new ECDomainParameters(ecP.Curve, ecP.G, ecP.N, ecP.H, ecP.GetSeed());
            var pGen     = new ECKeyPairGenerator();
            var genParam = new ECKeyGenerationParameters(
                eCDomainParameters,
                random);

            pGen.Init(genParam);
            var asymmetricCipherKeyPair = pGen.GenerateKeyPair();

            var senderPrivate = ((ECPrivateKeyParameters)asymmetricCipherKeyPair.Private).D.ToByteArray();
            var senderPublic  = ((ECPublicKeyParameters)asymmetricCipherKeyPair.Public).Q.GetEncoded();

            var asymmetricCipherKeyPairA = pGen.GenerateKeyPair();

            var recieverPrivate = ((ECPrivateKeyParameters)asymmetricCipherKeyPairA.Private).D.ToByteArray();

            var recieverPublic = ((ECPublicKeyParameters)asymmetricCipherKeyPairA.Public).Q.GetEncoded();

            var sharedSecret = GetSharedSecretValue(asymmetricCipherKeyPair, asymmetricCipherKeyPairA);

            var deriveSecret = DeriveSymmetricKeyFromSharedSecret(sharedSecret);

            var    encrypted = Encrypt(Encoding.UTF8.GetBytes(original), deriveSecret);
            var    roundtrip = Encoding.UTF8.GetString(Decrypt(encrypted, deriveSecret));
            string hex       = Epic.Converters.HexString.Encode(encrypted);
            string base64    = Convert.ToBase64String(encrypted);

            Console.WriteLine("Byte:   {0}", encrypted.Length);
            Console.WriteLine("Hex:   {0}, {1}", hex.Length, hex);
            Console.WriteLine("Base64:   {0}, {1}", base64.Length, base64);
            Console.WriteLine("Decode: {0}", roundtrip);
        }
示例#3
0
        public static X9ECParameters GetByName(string name)
        {
            X9ECParameters byName = X962NamedCurves.GetByName(name);

            if (byName == null)
            {
                byName = SecNamedCurves.GetByName(name);
            }
            if (byName == null)
            {
                byName = NistNamedCurves.GetByName(name);
            }
            if (byName == null)
            {
                byName = TeleTrusTNamedCurves.GetByName(name);
            }
            if (byName == null)
            {
                byName = AnssiNamedCurves.GetByName(name);
            }
            return(byName);
        }