Пример #1
0
        public async Task GenerateQrCode(string contactName)
        {
            IUserModel             user       = _storageService.GetUser();
            string                 publicKey  = RsaKeyTools.ExtractPublicKey(user.KeyPair);
            Tuple <string, string> pkElements = RsaKeyTools.DecomposePublicKey(publicKey);

            string contents = ComposeQrData(user.Id, contactName, pkElements.Item1, pkElements.Item2);

            IBarcodeWriter writer = QrTools.GetQrWriter();

            var matrix = writer.Encode(contents);
            var wb     = writer.Write(matrix);

            await PictureLibraryTools.SaveWriteableBitmap(wb, string.Format(QrCodeFileName, contactName));
        }
Пример #2
0
        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);
        }
Пример #3
0
 public string ExtractPublicKey(string keyPair)
 {
     return(RsaKeyTools.ExtractPublicKey(keyPair));
 }