Beispiel #1
0
        protected byte[] HashPassword(EncryptionInfo info,  string password)
        {
            HashAlgorithm sha1 = HashAlgorithm.Create("SHA1");

            byte[] bytes;
            try
            {
                bytes = Encoding.Unicode.GetBytes(password); //bytes = password.getBytes("UTF-16LE");
            }
            catch (CryptographicUnexpectedOperationException)
            {
                throw new EncryptedDocumentException("UTF16 not supported");
            }

            //sha1.ComputeHash(info.GetVerifier().Salt);
            byte[] salt = info.Verifier.Salt;
            byte[] temp = new byte[salt.Length + bytes.Length];
            Array.Copy(salt, temp, salt.Length);
            Array.Copy(bytes, 0, temp, salt.Length, bytes.Length);
            byte[] hash = sha1.ComputeHash(temp);
            byte[] iterator = new byte[4];
            temp = new byte[24];
            for (int i = 0; i < info.Verifier.SpinCount; i++)
            {
                //sha1.Clear();
                LittleEndian.PutInt(iterator, i);
                //sha1.iterator; //sha1.update(iterator);
                Array.Copy(iterator, temp, iterator.Length);
                Array.Copy(hash, 0, temp, iterator.Length, hash.Length);
                hash = sha1.ComputeHash(temp);
            }

            return hash;
        }
Beispiel #2
0
        public static Decryptor GetInstance(EncryptionInfo info)
        {
            int major = info.VersionMajor;
            int minor = info.VersionMinor;

            if (major == 4 && minor == 4)
                return new AgileDecryptor(info);
            else if (minor == 2 && (major == 3 || major == 4))
                return new EcmaDecryptor(info);
            else
                throw new EncryptedDocumentException("Unsupported version");
        }
Beispiel #3
0
 public EcmaDecryptor(EncryptionInfo info)
 {
     this.info = info;
 }
Beispiel #4
0
 public AgileDecryptor(EncryptionInfo info)
 {
     _info = info;
 }