Coverage Summary for Class: KeyCrypter (co.rsk.crypto)
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20
21 /*
22 * Copyright 2013 Jim Burton.
23 *
24 * Licensed under the MIT license (the "License")
25 * you may not use this file except in compliance with the License.
26 * You may obtain a copy of the License at
27 *
28 * http://opensource.org/licenses/mit-license.php
29 *
30 * Unless required by applicable law or agreed to in writing, software
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
35 */
36
37 package co.rsk.crypto;
38
39 import org.bouncycastle.crypto.params.KeyParameter;
40
41 import java.io.Serializable;
42
43 /**
44 * <p>A KeyCrypter can be used to encrypt and decrypt a message. The sequence of events to encrypt and then decrypt
45 * a message are as follows:</p>
46 *
47 * <p>(1) Encrypt the message using encrypt(), providing the message bytes and the KeyParameter from. This returns
48 * an EncryptedData which contains the encryptedPrivateKey bytes and an initialisation vector.</p>
49 * <p>(2) To decrypt an EncryptedData call decrypt() with the same from.</p>
50 */
51 public interface KeyCrypter extends Serializable {
52
53 /**
54 * Decrypt the provided encrypted bytes, converting them into unencrypted bytes.
55 *
56 * @throws KeyCrypterException if decryption was unsuccessful.
57 */
58 byte[] decrypt(EncryptedData encryptedBytesToDecode, KeyParameter key);
59
60 /**
61 * Encrypt the supplied bytes, converting them into ciphertext.
62 *
63 * @return An encryptedPrivateKey containing the encrypted bytes and an initialisation vector.
64 * @throws KeyCrypterException if encryption was unsuccessful
65 */
66 EncryptedData encrypt(byte[] plainBytes, KeyParameter key);
67 }