Coverage Summary for Class: EncryptedData (co.rsk.crypto)

Class Class, % Method, % Line, %
EncryptedData 100% (1/1) 25% (1/4) 30.8% (4/13)


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  * Copyright 2013 Jim Burton. 21  * 22  * Licensed under the MIT license (the "License") 23  * you may not use this file except in compliance with the License. 24  * You may obtain a copy of the License at 25  * 26  * http://opensource.org/licenses/mit-license.php 27  * 28  * Unless required by applicable law or agreed to in writing, software 29  * distributed under the License is distributed on an "AS IS" BASIS, 30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31  * See the License for the specific language governing permissions and 32  * limitations under the License. 33  */ 34  35 package co.rsk.crypto; 36  37 import com.google.common.base.Objects; 38 import java.util.Arrays; 39  40 /** 41  * <p>An instance of EncryptedData is a holder for an initialization vector and encrypted bytes. It is typically 42  * used to hold encrypted private key bytes.</p> 43  * 44  * <p>The initialisation vector is random data that is used to initialise the AES block cipher when the 45  * private key bytes were encrypted. You need these for decryption.</p> 46  */ 47 public final class EncryptedData { 48  public final byte[] initialisationVector; 49  public final byte[] encryptedBytes; 50  51  public EncryptedData(byte[] initialisationVector, byte[] encryptedBytes) { 52  this.initialisationVector = Arrays.copyOf(initialisationVector, initialisationVector.length); 53  this.encryptedBytes = Arrays.copyOf(encryptedBytes, encryptedBytes.length); 54  } 55  56  @Override 57  public boolean equals(Object o) { 58  if (this == o) { 59  return true; 60  } 61  62  if (o == null || getClass() != o.getClass()) { 63  return false; 64  } 65  66  EncryptedData other = (EncryptedData) o; 67  return Arrays.equals(encryptedBytes, other.encryptedBytes) && Arrays.equals(initialisationVector, other.initialisationVector); 68  } 69  70  @Override 71  public int hashCode() { 72  return Objects.hashCode(Arrays.hashCode(encryptedBytes), Arrays.hashCode(initialisationVector)); 73  } 74  75  @Override 76  public String toString() { 77  return "EncryptedData [initialisationVector=" + Arrays.toString(initialisationVector) 78  + ", encryptedPrivateKey=" + Arrays.toString(encryptedBytes) + "]"; 79  } 80 }