示例#1
0
        public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys)
        {
            Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral);
            Chain chain = chainAndIndex.first();

            Chain.Types.MessageKey messageKeyStructure = Chain.Types.MessageKey.CreateBuilder()
                                                         .SetCipherKey(ByteString.CopyFrom(messageKeys.getCipherKey() /*.getEncoded()*/))
                                                         .SetMacKey(ByteString.CopyFrom(messageKeys.getMacKey() /*.getEncoded()*/))
                                                         .SetIndex(messageKeys.getCounter())
                                                         .SetIv(ByteString.CopyFrom(messageKeys.getIv() /*.getIV()*/))
                                                         .Build();

            Chain updatedChain = chain.ToBuilder()
                                 .AddMessageKeys(messageKeyStructure)
                                 .Build();

            this.sessionStructure = this.sessionStructure.ToBuilder()
                                    .SetReceiverChains((int)chainAndIndex.second(), updatedChain)                      // TODO: conv
                                    .Build();
        }
        public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys)
        {
            Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral);
            Chain chain = chainAndIndex.first();

            Chain.Types.MessageKey messageKeyStructure = new Chain.Types.MessageKey
            {
                CipherKey = ByteString.CopyFrom(messageKeys.getCipherKey()),
                MacKey    = ByteString.CopyFrom(messageKeys.getMacKey()),
                Index     = messageKeys.getCounter(),
                Iv        = ByteString.CopyFrom(messageKeys.getIv())
            };

            chain.MessageKeys.Add(messageKeyStructure);
            if (chain.MessageKeys.Count > MAX_MESSAGE_KEYS)
            {
                chain.MessageKeys.RemoveAt(0);
            }

            sessionStructure.ReceiverChains[(int)chainAndIndex.second()] = chain;
        }
        public void setMessageKeys(ECPublicKey senderEphemeral, MessageKeys messageKeys)
        {
            Pair <Chain, uint> chainAndIndex = getReceiverChain(senderEphemeral);
            Chain chain = chainAndIndex.first();

            Chain.Types.MessageKey messageKeyStructure = Chain.Types.MessageKey.CreateBuilder()
                                                         .SetCipherKey(ByteString.CopyFrom(messageKeys.getCipherKey()))
                                                         .SetMacKey(ByteString.CopyFrom(messageKeys.getMacKey()))
                                                         .SetIndex(messageKeys.getCounter())
                                                         .SetIv(ByteString.CopyFrom(messageKeys.getIv()))
                                                         .Build();

            Chain.Builder updatedChain = chain.ToBuilder().AddMessageKeys(messageKeyStructure);
            if (updatedChain.MessageKeysList.Count > MAX_MESSAGE_KEYS)
            {
                updatedChain.MessageKeysList.RemoveAt(0);
            }

            sessionStructure = sessionStructure.ToBuilder()
                               .SetReceiverChains((int)chainAndIndex.second(), updatedChain.Build())
                               .Build();
        }
示例#4
0
        private byte[] getPlaintext(uint version, MessageKeys messageKeys, byte[] cipherText)
        {
            try
            {
                //Cipher cipher;

                if (version >= 3)
                {
                    //cipher = getCipher(Cipher.DECRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
                    return(Decrypt.aesCbcPkcs5(cipherText, messageKeys.getCipherKey(), messageKeys.getIv()));
                }
                else
                {
                    //cipher = getCipher(Cipher.DECRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getCounter())
                    return(Decrypt.aesCtr(cipherText, messageKeys.getCipherKey(), messageKeys.getCounter()));
                }

                //return cipher.doFinal(cipherText);
            }
            catch (/*IllegalBlockSizeException | BadPadding*/ Exception e)
            {
                throw new InvalidMessageException(e);
            }
        }
 private byte[] getCiphertext(uint version, MessageKeys messageKeys, byte[] plaintext)
 {
     try
     {
         if (version >= 3)
         {
             //cipher = getCipher(Cipher.ENCRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getIv());
             return(Encrypt.aesCbcPkcs5(plaintext, messageKeys.getCipherKey(), messageKeys.getIv()));
         }
         else
         {
             //cipher = getCipher(Cipher.ENCRYPT_MODE, messageKeys.getCipherKey(), messageKeys.getCounter());
             return(Encrypt.aesCtr(plaintext, messageKeys.getCipherKey(), messageKeys.getCounter()));
         }
     }
     catch (/*IllegalBlockSizeException | BadPadding*/ Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 private byte[] getPlaintext(MessageKeys messageKeys, byte[] cipherText)
 {
     return(Decrypt.aesCbcPkcs5(cipherText, messageKeys.getCipherKey(), messageKeys.getIv()));
 }
 private byte[] getCiphertext(MessageKeys messageKeys, byte[] plaintext)
 {
     return(Encrypt.aesCbcPkcs5(plaintext, messageKeys.getCipherKey(), messageKeys.getIv()));
 }
示例#8
0
 private byte[] getPlaintext(uint version, MessageKeys messageKeys, byte[] cipherText)
 {
     try
     {
         if (version >= 3)
         {
             return(Decrypt.aesCbcPkcs5(cipherText, messageKeys.getCipherKey(), messageKeys.getIv()));
         }
         else
         {
             return(Decrypt.aesCtr(cipherText, messageKeys.getCipherKey(), messageKeys.getCounter()));
         }
     }
     catch (Exception e)
     {
         throw new InvalidMessageException(e);
     }
 }
示例#9
0
 private byte[] getCiphertext(uint version, MessageKeys messageKeys, byte[] plaintext)
 {
     try
     {
         if (version >= 3)
         {
             return(Encrypt.aesCbcPkcs5(plaintext, messageKeys.getCipherKey(), messageKeys.getIv()));
         }
         else
         {
             return(Encrypt.aesCtr(plaintext, messageKeys.getCipherKey(), messageKeys.getCounter()));
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }