예제 #1
0
        /// <summary>
        /// Конструктор, использующийся для инициализации WebMoneyAccessor ключом Keeper Classic
        /// </summary>
        public WebMoneyAccessor()
        {
            var wmAccountDictionary = WebMoneyUtil.Instance.GetWmAccountSettings();

            if (wmAccountDictionary == null)
            {
                Logger.Error("WebMoneyAccessor() - не удалось прочитать необходимые для инициализировать WebMoney параметры (wmId, purseNumber и др.)");
                return;
            }

            keeperKeyValue    = wmAccountDictionary["WmKeeperKeyValue"].ToString();
            targetPurseNumber = (ulong)wmAccountDictionary["WmTargetPurseNumber"];
            wmId = (WmId)(ulong)wmAccountDictionary["WmId"];
            var targetPurseType = WebMoneyUtil.StrToCurrency(wmAccountDictionary["WmPurseCurrency"].ToString());

            purse = new Purse
            {
                Number = targetPurseNumber,
                Type   = targetPurseType
            };

            var keeperKey = new KeeperKey(keeperKeyValue);

            initializer = new Initializer(wmId, keeperKey)
            {
                StartDate = new DateTime(1983, 1, 1).ToUniversalTime()
            };
            initializer.Apply();

            wmServerTimeDifference = (WmDateTime.ServerTime2UtcTime(DateTime.Now).Hour - DateTime.Now.ToUniversalTime().Hour);
        }
        public void EncryptDecrypt()
        {
            const string xmlKey =
                "<RSAKeyValue><Modulus>VR//nsL+80zQAme+udfPanJjZuTJXbVid0Q8QntlnfAedr57TZnFjKSmCWJspJGU7sLs3VP1c0bs1uGw1MvW8G4F</Modulus><D>fbI2CL2ejA+o7a4CbClZGyKwzzfC/qcTsSm/C4hXwFkbvaTpsx0uzF+gj+Cd5qHlDGzum9Jn45AQzr1Y/qoou78A</D></RSAKeyValue>";

            const long wmId = 123456789012;

            string etalon;

            byte[] encrypted;

            using (var keeperKey = new DecryptedKey(xmlKey))
            {
                var signer = new Signer();
                signer.Initialize(keeperKey);

                etalon = signer.Sign("test", false);

                using (var secureString = new SecureString())
                {
                    secureString.AppendChar('ѕ');
                    secureString.AppendChar('а');
                    secureString.AppendChar('р');
                    secureString.AppendChar('о');
                    secureString.AppendChar('л');
                    secureString.AppendChar('ь');
                    secureString.AppendChar('1');
                    secureString.AppendChar('2');

                    secureString.MakeReadOnly();

                    encrypted = keeperKey.Encrypt(wmId, secureString);
                }
            }

            using (KeeperKey decryptedKey = DecryptedKey.Decrypt(encrypted, wmId, Encoding.GetBytes("ѕароль12")))
            {
                var signer = new Signer();
                signer.Initialize(decryptedKey);
                string signature = signer.Sign("test", false);

                Assert.AreEqual(etalon, signature);

                string decryptedXmlKey = decryptedKey.ToXmlString();

                Assert.AreEqual(xmlKey, decryptedXmlKey);
            }
        }
        public byte[] DecryptKeeperKey(byte[] encrypted, long id, string password)
        {
            if (null == encrypted)
            {
                throw new ArgumentNullException(nameof(encrypted));
            }

            if (id < 0 || id > 999999999999L)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            if (null == password)
            {
                throw new ArgumentNullException(nameof(password));
            }

            var idBytes =
                Encoding.Default.GetBytes(id.ToString("000000000000", CultureInfo.InvariantCulture.NumberFormat));
            var passwordBytes = Encoding.Default.GetBytes(password);

            KeeperKey keeperKey;

            try
            {
                var decryptedKey = new DecryptedKey(encrypted, idBytes, passwordBytes);
                keeperKey = new KeeperKey(decryptedKey.Modulus, decryptedKey.D);
            }
            catch (CryptographicException exception)
            {
                throw new WrongPasswordException(exception.Message, exception);
            }


            return(SerializationUtility.Serialize(keeperKey));
        }
 public WmExchangerVendor()
 {
     wmid        = WmId.Parse("320508520783");
     key         = new KeeperKey("<RSAKeyValue><Modulus>pV4KSuF3Tb7KrHeB+Mng4tRp14nw1HjuM/pBqa/YikNM7HBtwJaL9hUE5nZrcge8qjVU60jJyzPTPxEaenverjUM</Modulus><D>5bBcUTgYAzswW48F4eV6QpmscTKTBYvxasFem+NM+mlR2de+G5BO387ziYab09BtUypQKVYbJL9bewyqDqNufd8E</D></RSAKeyValue>");
     initializer = new Initializer(wmid, key);
 }