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

File PrivateKeyPasswordBasedEncryptor.java

 

Code metrics

0
0
0
1
145
29
0
-
-
0
-

Classes

Class Line # Actions
PrivateKeyPasswordBasedEncryptor 37 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

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.password;
21   
22    import java.io.IOException;
23    import java.security.GeneralSecurityException;
24   
25    import org.xwiki.component.annotation.Role;
26    import org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters;
27    import org.xwiki.crypto.params.cipher.symmetric.SymmetricCipherParameters;
28    import org.xwiki.crypto.password.params.KeyDerivationFunctionParameters;
29   
30    /**
31    * Manage encryption of private keys using password based ciphers as defined in PKCS #8.
32    *
33    * @version $Id: ed7c544be6fc8bdad9f908c9a1a363f373d05e6c $
34    * @since 5.4RC1
35    */
36    @Role
 
37    public interface PrivateKeyPasswordBasedEncryptor
38    {
39    /**
40    * Decrypt a private key from an encoded byte array.
41    *
42    * @param password the password used to derive the encryption key.
43    * @param encoded the encrypted key in ASN.1 format according to PKCS #8.
44    * @return decrypted private key parameters.
45    * @throws GeneralSecurityException if an error occurs during decryption.
46    * @throws IOException if an error occurs during decoding.
47    */
48    PrivateKeyParameters decrypt(byte[] password, byte[] encoded) throws GeneralSecurityException, IOException;
49   
50    /**
51    * Decrypt a private key from an {@link javax.crypto.EncryptedPrivateKeyInfo}.
52    *
53    * @param password the password used to derive the encryption key.
54    * @param privateKeyInfo the encrypted private key information.
55    * @return decrypted private key parameters.
56    * @throws GeneralSecurityException if an error occurs during decryption.
57    * @throws IOException if an error occurs during decoding.
58    */
59    PrivateKeyParameters decrypt(byte[] password, javax.crypto.EncryptedPrivateKeyInfo privateKeyInfo)
60    throws GeneralSecurityException, IOException;
61   
62    /**
63    * Encrypt a private key using a password based cipher in a PKCS #8 format.
64    *
65    * @param algHint the hint of the PasswordBasedCipher to use.
66    * @param password cipher parameters, using a password converted to bytes for the key.
67    * @param kdfParameters the parameters of the derivation function.
68    * @param privateKey the private key parameters to encrypt.
69    * @return the encrypted key in ASN.1 format according to PKCS #8.
70    * @throws GeneralSecurityException if an error occurs during encryption.
71    * @throws IOException if an error occurs during encoding.
72    */
73    byte[] encrypt(String algHint, SymmetricCipherParameters password,
74    KeyDerivationFunctionParameters kdfParameters, PrivateKeyParameters privateKey)
75    throws GeneralSecurityException, IOException;
76   
77    /**
78    * Encrypt a private key using a password based cipher in a PKCS #8 format.
79    *
80    * @param algHint the hint of the PasswordBasedCipher to use.
81    * @param password cipher parameters, using a password converted to bytes for the key.
82    * @param function the key derivation function to use for deriving key from password.
83    * @param privateKey cipher parameters, using a password converted to bytes for the key.
84    * @return the encrypted key in ASN.1 format according to PKCS #8.
85    * @throws GeneralSecurityException if an error occurs during encryption.
86    * @throws IOException if an error occurs during encoding.
87    */
88    byte[] encrypt(String algHint, SymmetricCipherParameters password,
89    KeyDerivationFunction function, PrivateKeyParameters privateKey)
90    throws GeneralSecurityException, IOException;
91   
92    /**
93    * Encrypt a private key using a password based cipher in a PKCS #8 format.
94    *
95    * @param algHint the hint of the PasswordBasedCipher to use.
96    * @param password the password used to derive the encryption key.
97    * @param encoded encoded parameters to initialize the cipher and derivation function.
98    * @param privateKey the private key parameters to encrypt.
99    * @return the encrypted key in ASN.1 format according to PKCS #8.
100    * @throws GeneralSecurityException if an error occurs during encryption.
101    * @throws IOException if an error occurs during encoding.
102    */
103    byte[] encrypt(String algHint, byte[] password, byte[] encoded, PrivateKeyParameters privateKey)
104    throws GeneralSecurityException, IOException;
105   
106    /**
107    * Encrypt a private key using a AES 256 password based cipher in a PKCS #8 format.
108    *
109    * @param password the password used to derive the encryption key.
110    * @param privateKey the private key parameters to encrypt.
111    * @return the encrypted key in ASN.1 format according to PKCS #8.
112    * @throws GeneralSecurityException if an error occurs during encryption.
113    * @throws IOException if an error occurs during encoding.
114    */
115   
116    byte[] encrypt(byte[] password, PrivateKeyParameters privateKey)
117    throws GeneralSecurityException, IOException;
118   
119    /**
120    * Encrypt a private key using a password based cipher in a PKCS #8 format.
121    *
122    * @param cipher the initialized PasswordBasedCipher to use.
123    * @param privateKey the private key parameters to encrypt.
124    * @return the encrypted key in ASN.1 format according to PKCS #8.
125    * @throws GeneralSecurityException if an error occurs during encryption.
126    * @throws IOException if an error occurs during encoding.
127    */
128    byte[] encrypt(PasswordBasedCipher cipher, PrivateKeyParameters privateKey)
129    throws IOException, GeneralSecurityException;
130   
131    /**
132    * Encrypt a private key in a PKCS #8 format using a random initialization vector.
133    *
134    * @param algHint the hint of the PasswordBasedCipher to use.
135    * @param password the password used to derive the encryption key.
136    * @param kdfParameters the parameters of the derivation function.
137    * @param privateKey the private key parameters to encrypt.
138    * @return the encrypted key in ASN.1 format according to PKCS #8.
139    * @throws GeneralSecurityException if an error occurs during encryption.
140    * @throws IOException if an error occurs during encoding.
141    */
142    byte[] encrypt(String algHint, byte[] password, KeyDerivationFunctionParameters kdfParameters,
143    PrivateKeyParameters privateKey)
144    throws IOException, GeneralSecurityException;
145    }