예제 #1
0
        public void VerifyMissionDetails()
        {
            MissionDetails missionDetails = GetMissionDetails();

            VerifySignature(missionDetails);
            string decryptedMessage = DecryptKey(missionDetails);

            DecryptedMessageResponse = GetResponse(decryptedMessage);
        }
예제 #2
0
        private void VerifySignature(MissionDetails missionDetails)
        {
            byte[] encryptedMessage = missionDetails.EncryptedMessage.FromBase64();

            SHA256 sha = SHA256.Create();

            byte[] hash = sha.ComputeHash(encryptedMessage);

            string xml = File.ReadAllText("ACMEpublickey.xml");

            RSA rsa = RSA.Create(2048);

            rsa.FromXmlString(xml);
            AcmePublicKey = rsa.ExportParameters(false);
            bool result = rsa.VerifyHash(hash, missionDetails.Signature.FromBase64(), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

            if (result == false)
            {
                throw new Exception("Failed Signature");
            }
        }
예제 #3
0
        private string DecryptKey(MissionDetails missionDetails)
        {
            byte[] encryptedkey = missionDetails.EncryptedKey.FromBase64();
            byte[] decryptedkey;

            using (RSA rsa = RSA.Create())
            {
                rsa.ImportParameters(MyPrivateKey);
                decryptedkey = rsa.Decrypt(encryptedkey, RSAEncryptionPadding.Pkcs1);
            }

            Aes aes = Aes.Create();

            aes.Key = decryptedkey;

            aes.IV = missionDetails.IV.FromBase64();

            ICryptoTransform decryptor = aes.CreateDecryptor();


            byte[] decryptedMessageBytes;

            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write))
                {
                    byte[] encryptedMissionBytes = missionDetails.EncryptedMessage.FromBase64();
                    cs.Write(encryptedMissionBytes, 0, encryptedMissionBytes.Length);
                }

                decryptedMessageBytes = ms.ToArray();
            }

            string decryptedMessage = decryptedMessageBytes.GetString();

            VerifyMissionString(decryptedMessage, missionDetails.MissionHash);

            return(decryptedMessage);
        }