internal StandardEncryptionHeader(ILittleEndianInput is1) { Flags = (is1.ReadInt()); SizeExtra = (is1.ReadInt()); CipherAlgorithm = (CipherAlgorithm.FromEcmaId(is1.ReadInt())); HashAlgorithm = (HashAlgorithm.FromEcmaId(is1.ReadInt())); int keySize = is1.ReadInt(); if (keySize == 0) { // for the sake of inheritance of the cryptoAPI classes // see 2.3.5.1 RC4 CryptoAPI Encryption Header // If Set to 0x00000000, it MUST be interpreted as 0x00000028 bits. keySize = 0x28; } KeySize = (keySize); BlockSize = (keySize); CipherProvider = (CipherProvider.FromEcmaId(is1.ReadInt())); is1.ReadLong(); // skip reserved // CSPName may not always be specified // In some cases, the salt value of the EncryptionVerifier is the next chunk of data ((ByteArrayInputStream)is1).Mark(LittleEndianConsts.INT_SIZE + 1); int CheckForSalt = is1.ReadInt(); ((ByteArrayInputStream)is1).Reset(); if (CheckForSalt == 16) { CspName = (""); } else { StringBuilder builder = new StringBuilder(); while (true) { char c = (char)is1.ReadShort(); if (c == 0) { break; } builder.Append(c); } CspName = (builder.ToString()); } ChainingMode = (ChainingMode.ecb); KeySalt = (null); }
public void Test() { Assert.AreEqual(128, CipherAlgorithm.aes128.defaultKeySize); foreach (CipherAlgorithm alg in CipherAlgorithm.Values) { Assert.AreEqual(alg, CipherAlgorithm.ValueOf(alg.ToString())); } Assert.AreEqual(CipherAlgorithm.aes128, CipherAlgorithm.FromEcmaId(0x660E)); Assert.AreEqual(CipherAlgorithm.aes192, CipherAlgorithm.FromXmlId("AES", 192)); try { CipherAlgorithm.FromEcmaId(0); Assert.Fail("Should throw exception"); } catch (EncryptedDocumentException) { // expected } try { CipherAlgorithm.FromXmlId("AES", 1); Assert.Fail("Should throw exception"); } catch (EncryptedDocumentException) { // expected } try { CipherAlgorithm.FromXmlId("RC1", 0x40); Assert.Fail("Should throw exception"); } catch (EncryptedDocumentException) { // expected } }