Esempio n. 1
0
        public bool Authenticate(KeyPair authenticationKeyPair, string signedText)
        {
            _rsaCryptoServiceProvider.FromXmlString(authenticationKeyPair.Public.Key);
            string signature = CryptoHelpers.ExtractSignature(signedText);
            string message   = CryptoHelpers.StripSignature(signedText);

            if (string.IsNullOrEmpty(signature))
            {
                throw new Exception("Digital signature is missing or not formatted properly.");
            }

            var bytes    = TextHelpers.ClearTextToClearBytes(message);
            var sigbytes = TextHelpers.CipherTextToCipherBytes(signature);

            return(_rsaCryptoServiceProvider.VerifyData(bytes, HashAlgorithm.Create(), sigbytes));
        }
Esempio n. 2
0
        public string Decrypt(KeyPair decryptionKeyPair, string cipherText)
        {
            //they use THEIR private key to decrypt
            _rsaCryptoServiceProvider.FromXmlString(decryptionKeyPair.Private.Key);

            var blockSize    = GetModulusSize();
            var plainStream  = new MemoryStream();
            var cipherStream = new MemoryStream(TextHelpers.CipherTextToCipherBytes(cipherText));
            var buffer       = new byte[blockSize];

            int r;

            while ((r = cipherStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                var p = _rsaCryptoServiceProvider.Decrypt(buffer, false);
                plainStream.Write(p, 0, p.Length);
            }
            //TODO: getting extra data here. not sure why
            var clearBytes = plainStream.ToArray();

            return(TextHelpers.ClearBytesToClearString(clearBytes));
        }