Beispiel #1
0
        internal StandardEncryptionVerifier(ILittleEndianInput is1, StandardEncryptionHeader header)
        {
            int saltSize = is1.ReadInt();

            if (saltSize != 16)
            {
                throw new Exception("Salt size != 16 !?");
            }

            byte[] salt = new byte[16];
            is1.ReadFully(salt);
            SetSalt(salt);

            byte[] encryptedVerifier = new byte[16];
            is1.ReadFully(encryptedVerifier);
            SetEncryptedVerifier(encryptedVerifier);

            verifierHashSize = is1.ReadInt();

            byte[] encryptedVerifierHash = new byte[header.CipherAlgorithm.encryptedVerifierHashLength];
            is1.ReadFully(encryptedVerifierHash);
            SetEncryptedVerifierHash(encryptedVerifierHash);

            SpinCount       = (SPIN_COUNT);
            CipherAlgorithm = (header.CipherAlgorithm);
            ChainingMode    = (header.ChainingMode);
            EncryptedKey    = (null);
            HashAlgorithm   = (header.HashAlgorithm);
        }
Beispiel #2
0
 public EncryptionRecordInternal(EncryptionInfo info,
                                 StandardEncryptionHeader header, StandardEncryptionVerifier verifier)
 {
     this.info     = info;
     this.header   = header;
     this.verifier = verifier;
 }
Beispiel #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.aes128;
            }
            if (cipherAlgorithm != CipherAlgorithm.aes128 &&
                cipherAlgorithm != CipherAlgorithm.aes192 &&
                cipherAlgorithm != CipherAlgorithm.aes256)
            {
                throw new EncryptedDocumentException("Standard encryption only supports AES128/192/256.");
            }

            if (hashAlgorithm == null)
            {
                hashAlgorithm = HashAlgorithm.sha1;
            }
            if (hashAlgorithm != HashAlgorithm.sha1)
            {
                throw new EncryptedDocumentException("Standard encryption only supports SHA-1.");
            }
            if (chainingMode == null)
            {
                chainingMode = ChainingMode.ecb;
            }
            if (chainingMode != ChainingMode.ecb)
            {
                throw new EncryptedDocumentException("Standard encryption only supports ECB chaining.");
            }
            if (keyBits == -1)
            {
                keyBits = cipherAlgorithm.defaultKeySize;
            }
            if (blockSize == -1)
            {
                blockSize = cipherAlgorithm.blockSize;
            }
            bool found = false;

            foreach (int ks in cipherAlgorithm.allowedKeySize)
            {
                found |= (ks == keyBits);
            }
            if (!found)
            {
                throw new EncryptedDocumentException("KeySize " + keyBits + " not allowed for Cipher " + cipherAlgorithm.ToString());
            }
            header    = new StandardEncryptionHeader(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
            verifier  = new StandardEncryptionVerifier(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode);
            decryptor = new StandardDecryptor(this);
            encryptor = new StandardEncryptor(this);
        }
Beispiel #4
0
        protected internal void CreateEncryptionInfoEntry(DirectoryNode dir)
        {
            EncryptionInfo             info     = builder.GetEncryptionInfo();
            StandardEncryptionHeader   header   = builder.GetHeader();
            StandardEncryptionVerifier verifier = builder.GetVerifier();

            EncryptionRecord er = new EncryptionRecordInternal(info, header, verifier);


            DataSpaceMapUtils.CreateEncryptionEntry(dir, "EncryptionInfo", er);

            // TODO: any properties???
        }
Beispiel #5
0
        /**
         * Initialize the builder from a stream
         */
        public void Initialize(EncryptionInfo info, ILittleEndianInput dis)
        {
            this.info = info;

            int hSize = dis.ReadInt();

            header   = new StandardEncryptionHeader(dis);
            verifier = new StandardEncryptionVerifier(dis, header);

            if (info.VersionMinor == 2 && (info.VersionMajor == 3 || info.VersionMajor == 4))
            {
                decryptor = new StandardDecryptor(this);
            }
        }