1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.params.cipher.symmetric

File KeyWithIVParameters.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
12
9
1
131
46
9
0.75
1.33
9
1

Classes

Class Line # Actions
KeyWithIVParameters 30 12 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 30 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.params.cipher.symmetric;
21   
22    import java.security.SecureRandom;
23   
24    /**
25    * Symmetric cipher parameters for cipher requiring a key and an initialization vector.
26    *
27    * @version $Id: 101bdd151d7860fff4a083056f57fa47101d80b3 $
28    * @since 5.4M1
29    */
 
30    public class KeyWithIVParameters implements SymmetricCipherParameters
31    {
32    /** A encryption initialization vector. */
33    private final KeyParameter keyParam;
34   
35    private final byte[] iv;
36   
37    /**
38    * Initialize parameters with a random initialization vector.
39    *
40    * @param key the key.
41    * @param ivSize the size of the initialization vector.
42    */
 
43  6 toggle public KeyWithIVParameters(byte[] key, int ivSize)
44    {
45  6 this(new KeyParameter(key), ivSize);
46    }
47   
48    /**
49    * Initialize parameters.
50    *
51    * @param key the key.
52    * @param iv the initialization vector.
53    */
 
54  46 toggle public KeyWithIVParameters(byte[] key, byte[] iv)
55    {
56  46 this(new KeyParameter(key), iv);
57    }
58   
59    /**
60    * Initialize parameters.
61    *
62    * @param key the key.
63    * @param ivSize the size of the initialization vector to randomize.
64    * @param random the random source.
65    */
 
66  2 toggle public KeyWithIVParameters(byte[] key, int ivSize, SecureRandom random)
67    {
68  2 this(new KeyParameter(key), ivSize, random);
69    }
70   
71    /**
72    * Initialize parameters.
73    *
74    * @param key the key.
75    * @param ivSize the size of the initialization vector to randomize using a new default SecureRandom.
76    */
 
77  6 toggle public KeyWithIVParameters(KeyParameter key, int ivSize)
78    {
79  6 this(key, ivSize, new SecureRandom());
80    }
81   
82    /**
83    * Initialize parameters.
84    *
85    * @param key the key.
86    * @param ivSize the size of the initialization vector to randomize.
87    * @param random the random source.
88    */
 
89  8 toggle public KeyWithIVParameters(KeyParameter key, int ivSize, SecureRandom random)
90    {
91  8 this.keyParam = key;
92  8 this.iv = new byte[ivSize];
93  8 random.nextBytes(this.iv);
94    }
95   
96    /**
97    * Initialize parameters.
98    *
99    * @param key the key.
100    * @param iv the initialization vector.
101    */
 
102  63 toggle public KeyWithIVParameters(KeyParameter key, byte[] iv)
103    {
104  63 this.keyParam = key;
105  63 this.iv = iv;
106    }
107   
108    /**
109    * @return the initialization vector.
110    */
 
111  46 toggle public KeyParameter getKeyParameter()
112    {
113  46 return this.keyParam;
114    }
115   
116    /**
117    * @return the key.
118    */
 
119  46 toggle public byte[] getKey()
120    {
121  46 return this.keyParam.getKey();
122    }
123   
124    /**
125    * @return the initialization vector.
126    */
 
127  93 toggle public byte[] getIV()
128    {
129  93 return this.iv;
130    }
131    }