Ejemplo n.º 1
0
        public override void ConfirmPassword(String password, byte[] keySpec,
                                             byte[] keySalt, byte[] verifier, byte[] verifierSalt,
                                             byte[] integritySalt)
        {
            Debug.Assert(verifier != null && verifierSalt != null);
            CryptoAPIEncryptionVerifier ver = builder.GetVerifier();

            ver.SetSalt(verifierSalt);
            ISecretKey skey = CryptoAPIDecryptor.GenerateSecretKey(password, ver);

            SetSecretKey(skey);
            try
            {
                Cipher cipher            = InitCipherForBlock(null, 0);
                byte[] encryptedVerifier = new byte[verifier.Length];
                cipher.Update(verifier, 0, verifier.Length, encryptedVerifier);
                ver.SetEncryptedVerifier(encryptedVerifier);
                HashAlgorithm hashAlgo              = ver.HashAlgorithm;
                MessageDigest hashAlg               = CryptoFunctions.GetMessageDigest(hashAlgo);
                byte[]        calcVerifierHash      = hashAlg.Digest(verifier);
                byte[]        encryptedVerifierHash = cipher.DoFinal(calcVerifierHash);
                ver.SetEncryptedVerifierHash(encryptedVerifierHash);
            }
            catch (Exception e)
            {
                throw new EncryptedDocumentException("Password Confirmation failed", e);
            }
        }
Ejemplo n.º 2
0
        protected void CreateEncryptionInfoEntry(DirectoryNode dir)
        {
            DataSpaceMapUtils.AddDefaultDataSpace(dir);
            EncryptionInfo              info     = builder.GetEncryptionInfo();
            CryptoAPIEncryptionHeader   header   = builder.GetHeader();
            CryptoAPIEncryptionVerifier verifier = builder.GetVerifier();
            EncryptionRecord            er       = new EncryptionRecordInternal(info, header, verifier);

            DataSpaceMapUtils.CreateEncryptionEntry(dir, "EncryptionInfo", er);
        }
Ejemplo n.º 3
0
        /**
         * Initialize the builder from a stream
         */
        public void Initialize(EncryptionInfo info, ILittleEndianInput dis)
        {
            this.info = info;
            int hSize = dis.ReadInt();

            header    = new CryptoAPIEncryptionHeader(dis);
            verifier  = new CryptoAPIEncryptionVerifier(dis, header);
            decryptor = new CryptoAPIDecryptor(this);
            encryptor = new CryptoAPIEncryptor(this);
        }
Ejemplo n.º 4
0
        /**
         * Initialize the builder from scratch
         */
        public void Initialize(EncryptionInfo info,
                               CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm,
                               int keyBits, int blockSize, ChainingMode chainingMode)
        {
            this.info = info;
            if (cipherAlgorithm == null)
            {
                cipherAlgorithm = CipherAlgorithm.rc4;
            }
            if (hashAlgorithm == null)
            {
                hashAlgorithm = HashAlgorithm.sha1;
            }
            if (keyBits == -1)
            {
                keyBits = 0x28;
            }
            Debug.Assert(cipherAlgorithm == CipherAlgorithm.rc4 && hashAlgorithm == HashAlgorithm.sha1);

            header    = new CryptoAPIEncryptionHeader(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
            verifier  = new CryptoAPIEncryptionVerifier(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
            decryptor = new CryptoAPIDecryptor(this);
            encryptor = new CryptoAPIEncryptor(this);
        }