View Javadoc
1   /*
2   Copyright (c) 2013 James Ahlborn
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.crypt.impl.office;
18  
19  import java.nio.ByteBuffer;
20  
21  import com.healthmarketscience.jackcess.crypt.InvalidCryptoConfigurationException;
22  import com.healthmarketscience.jackcess.impl.ByteUtil;
23  
24  /**
25   *
26   * @author James Ahlborn
27   */
28  public class EncryptionVerifier
29  {
30    private final static int SALT_SIZE = 16;
31    private final static int ENC_VERIFIER_SIZE = 16;
32  
33    private final int _saltSize;
34    private final byte[] _salt;
35    private final byte[] _encryptedVerifier;
36    private final int _verifierHashSize;
37    private final byte[] _encryptedVerifierHash;
38  
39    public EncryptionVerifier(ByteBuffer buffer,
40                              EncryptionHeader.CryptoAlgorithm cryptoAlg)
41    {
42      // OC: 2.3.3 EncryptionVerifier Structure
43      _saltSize = buffer.getInt();
44      if(_saltSize != SALT_SIZE) {
45        throw new InvalidCryptoConfigurationException("salt size " + _saltSize + " must be " + SALT_SIZE);
46      }
47      _salt = ByteUtil.getBytes(buffer, _saltSize);
48      _encryptedVerifier = ByteUtil.getBytes(buffer, ENC_VERIFIER_SIZE);
49      _verifierHashSize = buffer.getInt();
50      _encryptedVerifierHash = ByteUtil.getBytes(
51          buffer, cryptoAlg.getEncryptedVerifierHashLen());
52    }
53  
54    public int getSaltSize() {
55      return _saltSize;
56    }
57  
58    public byte[] getSalt() {
59      return _salt;
60    }
61  
62    public byte[] getEncryptedVerifier() {
63      return _encryptedVerifier;
64    }
65  
66    public int getVerifierHashSize() {
67      return _verifierHashSize;
68    }
69  
70    public byte[] getEncryptedVerifierHash() {
71      return _encryptedVerifierHash;
72    }
73  
74  }