コード例 #1
0
 protected virtual void Dispose(bool disposing)
 {
     _keyset          = _keyset.SafeDispose();
     _crypter         = _crypter.SafeDispose();
     _signer          = _signer.SafeDispose();
     _verifier        = _verifier.SafeDispose();
     _nonce           = _nonce.Clear();
     _sessionMaterial = _sessionMaterial.Clear();
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionCrypter" /> class.
        /// </summary>
        /// <param name="keyDecrypter">The key decrypter.</param>
        /// <param name="sessionMaterial">The session material.</param>
        /// <param name="verifier">The verifier, optionally used to certify sender. (Equivialent to SignedSessionDecrypter)</param>
        /// <param name="keyPacker">The key packer.</param>
        public SessionCrypter(Crypter keyDecrypter, WebBase64 sessionMaterial, AttachedVerifier verifier = null,
                              ISessionKeyPacker keyPacker = null)
        {
            Workings initLazy()
            {
                var workings = new Workings();

                if (verifier != null)
                {
                    keyPacker = keyPacker ?? new NonceSignedSessionPacker();
                }
                keyPacker = keyPacker ?? new SimpleAesHmacSha1KeyPacker();

                var sessionMaterialBytes = sessionMaterial.ToBytes();
                var sessionPacker        = keyPacker as IInteroperableSessionMaterialPacker;

                workings._verifier = verifier;

                if (sessionPacker == null && workings._verifier != null)
                {
                    sessionMaterialBytes = workings._verifier.VerifiedMessage(sessionMaterialBytes);
                }
                var packedBytes = keyDecrypter.Decrypt(sessionMaterialBytes);

                Key key;

                if (sessionPacker == null)
                {
                    key = keyPacker.Unpack(packedBytes, Config);
                }
                else
                {
                    var nonceSession = sessionPacker.UnpackMaterial(packedBytes, Config);
                    key             = nonceSession.Key;
                    workings._nonce = nonceSession.Nonce.ToBytes();
                }

                workings._keyset          = new ImportedKeySet(key, KeyPurpose.DecryptAndEncrypt);
                workings._crypter         = new Crypter(workings._keyset);
                workings._sessionMaterial = sessionMaterial;
                return(workings);
            }

            _working = new Lazy <Workings>(initLazy);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionCrypter" /> class.
        /// </summary>
        /// <param name="keyDecrypter">The key decrypter.</param>
        /// <param name="sessionMaterial">The session material.</param>
        /// <param name="verifier">The verifier, optionally used to certify sender. (Equivialent to SignedSessionDecrypter)</param>
        /// <param name="keyPacker">The key packer.</param>
        public SessionCrypter(Crypter keyDecrypter, WebBase64 sessionMaterial, AttachedVerifier verifier = null,
                              ISessionKeyPacker keyPacker = null)
        {
            if (verifier != null)
            {
                keyPacker = keyPacker ?? new NonceSignedSessionPacker();
            }
            keyPacker = keyPacker ?? new SimpleAesHmacSha1KeyPacker();

            var sessionMaterialBytes = sessionMaterial.ToBytes();
            var sessionPacker        = keyPacker as IInteroperableSessionMaterialPacker;

            _verifier = verifier;

            if (sessionPacker == null && _verifier != null)
            {
                sessionMaterialBytes = _verifier.VerifiedMessage(sessionMaterialBytes);
            }
            var packedBytes = keyDecrypter.Decrypt(sessionMaterialBytes);

            Key key;

            if (sessionPacker == null)
            {
                key = keyPacker.Unpack(packedBytes);
            }
            else
            {
                var nonceSession = sessionPacker.UnpackMaterial(packedBytes);
                key    = nonceSession.Key;
                _nonce = nonceSession.Nonce.ToBytes();
            }

            _keyset          = new ImportedKeySet(key, KeyPurpose.DecryptAndEncrypt);
            _crypter         = new Crypter(_keyset);
            _sessionMaterial = sessionMaterial;
        }