Exemple #1
0
        public static void Test()
        {
            string npv, npu, nad;

            CryptographyHelper.GenerateKeys(out npu, out npv, out nad, AddressFamily.NMC, "C");

            string npv2, npu2, nad2;

            CryptographyHelper.GenerateKeys(out npu2, out npv2, out nad2);

            //npv2 = string.Join("", npv2.Take(3).ToArray()) + "5" + string.Join("", npv2.Skip(4).TakeWhile(f => true).ToArray());
            var rce = DecryptElliptical(EncryptElliptical("test me", npu, npv2), npu2, npv); //works

            var test = @"can you please sign this statement";
            var rse  = VerifyElliptical(test, npu, SignWithElliptical(test, npv));

            string pv, pu;

            CryptographyHelper.GenerateKeys(out pu, out pv);
            var s       = CryptographyHelper.Encrypt("asdad", pu);
            var y       = CryptographyHelper.Decrypt(s, pv);
            var x       = CryptographyHelper.SignWithPrivateKey("y", pv);
            var session = Convert.ToBase64String(x);
            var z       = CryptographyHelper.Verify("yy", pu, x);
            //Console.WriteLine("Done.");
            //Console.ReadLine();

            var sr = new CNX.Shared.Models.SessionRequest {
                CompanyID = Guid.NewGuid()
            };
            var nonce = GuidHelper.Nonce;
            var sk    = CryptographyHelper.GenerateKey(256);
            var enc   = CryptographyHelper.EncryptSymmetric <CNX.Shared.Models.SessionRequest>(sr, sk, nonce);
            var dev   = CryptographyHelper.DecryptSymmetric <CNX.Shared.Models.SessionRequest>(enc, sk, nonce);
        }
Exemple #2
0
        public static ILicence GetContactInfo(SessionRequest m)
        {
            IStateName proxy = XmlRpcProxyGen.Create <IStateName>();

            proxy.Url = ConstantsHelper.PROVIDER_URL_DEFAULT;
            m.Nonce   = GuidHelper.Nonce;
            var response = proxy.GetContactInfo(m.Encrypt <SessionRequest>(ConstantsHelper.KEY_PUBLIC_DEFAULT));

            if (string.IsNullOrWhiteSpace(response))
            {
                throw new System.Security.SecurityException("Could not retrieve secure contact details from service.");
            }
            return(CryptographyHelper.VerifyAndDeserialize <SessionRequest>(response, ConstantsHelper.KEY_PUBLIC_DEFAULT));
        }
Exemple #3
0
        public static ISession RenewSession(SessionRequest m)
        {
            IStateName proxy = XmlRpcProxyGen.Create <IStateName>();

            proxy.Url     = ConstantsHelper.PROVIDER_URL_DEFAULT;
            m.Nonce       = GuidHelper.Nonce;
            m.MachineHash = Convert.ToBase64String(MachineHelper.GetMachineHash());
            var response = proxy.RenewSession(m.Encrypt <SessionRequest>(ConstantsHelper.KEY_PUBLIC_DEFAULT));

            if (string.IsNullOrWhiteSpace(response))
            {
                return(null);
            }
            return(CryptographyHelper.VerifyAndDeserialize <SessionRequest>(response, ConstantsHelper.KEY_PUBLIC_DEFAULT));
        }