Ejemplo n.º 1
0
        public Message AuthenticateMessage(string message)
        {
            HMACManager             DigestKey = new HMACManager(Helper.GetDigestKey());
            JsonCryptoDigestMessage jsonCryptoDigestMessage = JsonConvert.DeserializeObject <JsonCryptoDigestMessage>(message);

            if (!jsonCryptoDigestMessage.Digest.Equals(DigestKey.Encode(jsonCryptoDigestMessage.Message)))
            {
                throw new Exception("Message was corrupted!\n");
            }

            return(JsonConvert.DeserializeObject <Message>(jsonCryptoDigestMessage.Message));
        }
Ejemplo 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))));
        }