예제 #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);
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 /**
  * Initializes a cipher object for a given block index for encryption
  *
  * @param cipher may be null, otherwise the given instance is reset to the new block index
  * @param block the block index, e.g. the persist/slide id (hslf)
  * @return a new cipher object, if cipher was null, otherwise the reInitialized cipher
  * @throws GeneralSecurityException
  */
 public Cipher InitCipherForBlock(Cipher cipher, int block)
 {
     return(CryptoAPIDecryptor.InitCipherForBlock(cipher, block, builder, GetSecretKey(), Cipher.ENCRYPT_MODE));
 }