Exemplo n.º 1
0
        public string DecodeAndDecryptMessage(string msg)
        {
            RSAManager RSAKeys = new RSAManager(Helper.GetPublicKey().RSAParameters, Helper.GetPrivateKey());
            Message    message = AuthenticateMessage(msg);

            //Decipher symm key to decipher the content
            string      keyToDecipher = RSAKeys.Decrypt(message.KeyToDecipher);
            KeyDecipher keyDecipher   = JsonConvert.DeserializeObject <KeyDecipher>(keyToDecipher);

            //Decipher content
            AesManager aesManager = new AesManager();

            aesManager.Update(keyDecipher.Key, keyDecipher.IV);

            byte[] content = JsonConvert.DeserializeObject <byte[]>(message.Cryptotext);
            string Content = aesManager.DecryptStringFromBytes_Aes(content);

            JsonFreshMessage jsonFreshMessage = JsonConvert.DeserializeObject <JsonFreshMessage>(Content);

            VerifyNonce(jsonFreshMessage.Nonce);

            return(jsonFreshMessage.Message);
        }
Exemplo n.º 2
0
        public string JsonMessage(string msg)
        {
            RSAManager RSAKeys    = new RSAManager(Helper.GetPcPublicKey());
            AesManager aesManager = new AesManager();

            //Cipher content with the symmetric key
            byte[] bytes      = aesManager.EncryptStringToBytes_Aes(msg);
            string cipherText = JsonConvert.SerializeObject(bytes);

            //Cipher the symmetric key with pub key
            KeyDecipher keyDecipher = new KeyDecipher(aesManager.Key, aesManager.InitVect);
            string      KeyDecipher = JsonConvert.SerializeObject(keyDecipher);
            string      cipheredKey = RSAKeys.Encrypt(KeyDecipher);

            //The cipherText and cipherKey
            Message message = new Message(cipherText, cipheredKey);
            string  Message = JsonConvert.SerializeObject(message);

            //Digest the message
            HMACManager DigestKey = new HMACManager(Helper.GetDigestKey());

            return(JsonConvert.SerializeObject(new JsonCryptoDigestMessage(Message, DigestKey.Encode(Message))));
        }