Exemplo n.º 1
0
        /// <summary>
        /// Creates a simmetric encrypted sequence
        /// </summary>
        /// <param name="alKeys">keys to produce the sequence for</param>
        /// <param name="aaAction">encrypt/sign</param>
        /// <param name="saAlgo">algorithm used</param>
        /// <param name="bSymKey">simmetric key</param>
        /// <returns>a simmetric encrypted sequence</returns>
        private static ESKSequence CreateESKSequence(ArrayList alKeys, AsymActions aaAction, SymAlgorithms saAlgo, byte[] bSymKey)
        {
            IEnumerator ieKeys = alKeys.GetEnumerator();
            ESKSequence esksReturn = new ESKSequence();

            while (ieKeys.MoveNext()) {
                TransportablePublicKey tpkKey = (TransportablePublicKey)ieKeys.Current;
                PublicKeyPacket pkpKey = tpkKey.FindKey(aaAction);

                if (pkpKey == null)
                    throw new Exception("Could not find subkey fitting to the selected action. Concerned Key: " + tpkKey.PrimaryUserID);

                AsymSessionKeyPacket skpKey = new AsymSessionKeyPacket();
                skpKey.KeyID = pkpKey.KeyID;
                skpKey.PublicAlgorithm = pkpKey.Algorithm;
                skpKey.SymmetricAlgorithm = saAlgo;
                skpKey.SessionKey = bSymKey;

                skpKey.EncryptSessionKey(pkpKey);

                esksReturn.AddAsymSessionKey(skpKey);
            }

            return esksReturn;
        }
Exemplo n.º 2
0
        private ESKSequence CreateESKSequence(TransportablePublicKey[] tpkKeys, AsymActions aaAction, SymAlgorithms saAlgo, byte[] bSymKey)
        {
            ESKSequence esksReturn = new ESKSequence();

            for (int i=0; i<tpkKeys.Length; i++) {
                TransportablePublicKey tpkKey = tpkKeys[i];
                PublicKeyPacket pkpKey = tpkKey.FindKey(aaAction);

                if (pkpKey == null)
                    throw new Exception("Could not find subkey fitting to the selected action. Concerned Key: " + tpkKey.PrimaryUserID);

                AsymSessionKeyPacket skpKey = new AsymSessionKeyPacket();
                skpKey.KeyID = pkpKey.KeyID;
                skpKey.PublicAlgorithm = pkpKey.Algorithm;
                skpKey.SymmetricAlgorithm = saAlgo;
                skpKey.SessionKey = bSymKey;

                skpKey.EncryptSessionKey(pkpKey);

                esksReturn.AddAsymSessionKey(skpKey);
            }

            return esksReturn;
        }