示例#1
0
        public static Akep2Message3 FromString(string str, byte[] longTermKey)
        {
            var contentBytes       = PemParser.GetMessageContentBytes(str);
            var contentObjectsList = (List <object>)SksAsn1Parser.Parse(contentBytes);

            var iv            = (byte[])contentObjectsList[0];
            var encryptedPart = (byte[])contentObjectsList[1];
            var hmacPart      = (byte[])contentObjectsList[2];

            var myHmac = SksHmac.Hash(longTermKey, encryptedPart);

            if (!Utils.CompareByteArrays(hmacPart, myHmac))
            {
                Logger.Log("AKEP2MESSAGE2:", "Hmac doesn't match");
                return(null);
            }

            var decryptedSequence = SksAes.DecryptBytesFromBytes_Aes(encryptedPart, longTermKey, iv);

            contentObjectsList = (List <object>)SksAsn1Parser.Parse(decryptedSequence);

            var a      = (string)contentObjectsList[0];
            var nonceB = (byte[])contentObjectsList[1];

            return(new Akep2Message3(a, nonceB, longTermKey));
        }
示例#2
0
        public void SendChatMessage(string message)
        {
            Logger.Log(GetWholeLogTag(), $"SendChatMessage - Message: {message}");

            var secret = GetSecretFromProtocol();

            if (secret == null)
            {
                Logger.Log("USER:"******"Secret is null");
                return;
            }


            var iv = Utils.GenerateRandom16();
            var encryptedMessageBytes = SksAes.EncryptStringToBytes_Aes(message, secret, iv);
            var hmacBytes             = SksHmac.Hash(secret, Utils.StringToBytes(message));

            Logger.Log(GetWholeLogTag(), $"SendChatMessage - EcnryptedBytes: {string.Join(",", encryptedMessageBytes)}");
            Logger.Log(GetWholeLogTag(), $"SendChatMessage - Hmac: {string.Join(",", hmacBytes)}");

            var chatMessage  = new ChatMessage(iv, encryptedMessageBytes, hmacBytes);
            var finalMessage = chatMessage.ToString();

            Client.SendMessage(finalMessage);
        }
示例#3
0
        public byte[] GetSecret()
        {
            var key = keyBytes.ToList();

            key[key.Count - 1]++;
            // todo: nonceB je null
            return(SksHmac.Hash(key.ToArray(), NonceB));
        }
示例#4
0
        public Akep2Message3(string a, byte[] nonceB, byte[] longTermKey)
        {
            Iv = Utils.GenerateRandom16();

            A      = a;
            NonceB = nonceB;

            var objects = new List <object> {
                A, NonceB
            };

            var sequence = SksAsn1Encoder.EncodeSequence(objects);

            EncryptedPart = SksAes.EncryptBytes_Aes(sequence, longTermKey, Iv);
            HmacPart      = SksHmac.Hash(longTermKey, sequence);
        }