コード例 #1
0
ファイル: GroupCipher.cs プロジェクト: isp1r0/libaxolotl-uwp
        /**
         * Encrypt a message.
         *
         * @param paddedPlaintext The plaintext message bytes, optionally padded.
         * @return Ciphertext.
         * @throws NoSessionException
         */
        public byte[] encrypt(byte[] paddedPlaintext)
        {
            lock (LOCK)
            {
                try
                {
                    SenderKeyRecord  record         = senderKeyStore.loadSenderKey(senderKeyId);
                    SenderKeyState   senderKeyState = record.getSenderKeyState();
                    SenderMessageKey senderKey      = senderKeyState.getSenderChainKey().getSenderMessageKey();
                    byte[]           ciphertext     = getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);

                    SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(),
                                                                             senderKey.getIteration(),
                                                                             ciphertext,
                                                                             senderKeyState.getSigningKeyPrivate());

                    senderKeyState.setSenderChainKey(senderKeyState.getSenderChainKey().getNext());

                    senderKeyStore.storeSenderKey(senderKeyId, record);

                    return(senderKeyMessage.serialize());
                }
                catch (InvalidKeyIdException e)
                {
                    throw new NoSessionException(e);
                }
            }
        }
コード例 #2
0
ファイル: SenderKeyState.cs プロジェクト: jmue/libaxolotl-uwp
        public void addSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
                SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
                .SetIteration(senderMessageKey.getIteration())
                .SetSeed(ByteString.CopyFrom(senderMessageKey.getSeed()))
                .Build();

            this.senderKeyStateStructure = this.senderKeyStateStructure.ToBuilder()
                                           .AddSenderMessageKeys(senderMessageKeyStructure)
                                           .Build();
        }
コード例 #3
0
        public void addSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure = new SenderKeyStateStructure.Types.SenderMessageKey
            {
                Iteration = senderMessageKey.getIteration(),
                Seed      = ByteString.CopyFrom(senderMessageKey.getSeed())
            };
            this.senderKeyStateStructure.SenderMessageKeys.Add(senderMessageKeyStructure);

            if (senderKeyStateStructure.SenderMessageKeys.Count > MAX_MESSAGE_KEYS)
            {
                senderKeyStateStructure.SenderMessageKeys.RemoveAt(0);
            }
        }
コード例 #4
0
        public void addSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
                SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
                .SetIteration(senderMessageKey.getIteration())
                .SetSeed(ByteString.CopyFrom(senderMessageKey.getSeed()))
                .Build();

            SenderKeyStateStructure.Builder builder = this.senderKeyStateStructure.ToBuilder();
            builder.AddSenderMessageKeys(senderMessageKeyStructure);

            if (builder.SenderMessageKeysList.Count > MAX_MESSAGE_KEYS)
            {
                builder.SenderMessageKeysList.RemoveAt(0);
            }
            this.senderKeyStateStructure = builder.Build();
        }