コード例 #1
0
        public void AddContact(QrContact contact)
        {
            _storageService.SaveContacts(new[] { new ContactItem
                                                 {
                                                     Id        = contact.UserId,
                                                     PublicKey = contact.PublicKey,
                                                     IsNew     = true,
                                                     Name      = contact.Name
                                                 } });

            var me = _storageService.GetUser();

            _client.AddContact(new Contact
            {
                Name       = me.Name ?? string.Empty,
                PublicKey  = _encryptionService.ExtractPublicKey(me.KeyPair),
                ReceiverId = contact.UserId,
                SenderId   = me.Id
            });
        }
コード例 #2
0
ファイル: QrService.cs プロジェクト: QRyptoWire/qrypto-wire
        public bool ParseQrCode(string qrData, out QrContact contact)
        {
            contact = null;

            string[] elements = DecomposeQrData(qrData);

            if (elements?.Length != QrElements.Count)
            {
                return(false);
            }

            int userId;

            if (!Int32.TryParse(elements[QrElements.IdIndex], NumberStyles.None, CultureInfo.InvariantCulture, out userId))
            {
                return(false);
            }

            if (userId == _storageService.GetUser().Id)
            {
                return(false);
            }

            string name     = elements[QrElements.NameIndex];
            string modulus  = elements[QrElements.ModulusIndex];
            string exponent = elements[QrElements.ExponentIndex];

            string publicKey;

            if (!RsaKeyTools.ComposePublicKey(modulus, exponent, out publicKey))
            {
                return(false);
            }

            contact = new QrContact()
            {
                Name = name, PublicKey = publicKey, UserId = userId
            };
            return(true);
        }