001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.util.common.persistence; 018 019import java.io.Serializable; 020import javax.crypto.SecretKey; 021 022public class BaseKeys 023 implements Serializable { 024 025 private BaseKey baseKey1; 026 private BaseKey baseKey2; 027 private BaseKey baseKey3; 028 private String baseEncryptionKeyName; 029 030 private void init(BaseKey baseKey1, BaseKey baseKey2, BaseKey baseKey3, String baseEncryptionKeyName) { 031 this.setBaseKey1(baseKey1); 032 this.setBaseKey2(baseKey2); 033 this.setBaseKey3(baseKey3); 034 this.setBaseEncryptionKeyName(baseEncryptionKeyName); 035 } 036 037 /** Creates a new instance of BaseKeys */ 038 public BaseKeys(BaseKey baseKey1, BaseKey baseKey2, BaseKey baseKey3, String baseEncryptionKeyName) { 039 init(baseKey1, baseKey2, baseKey3, baseEncryptionKeyName); 040 } 041 042 /** Creates a new instance of BaseKeys */ 043 public BaseKeys(BaseKey baseKey1, BaseKey baseKey2, BaseKey baseKey3) { 044 init(baseKey1, baseKey2, baseKey3, null); 045 } 046 047 /** Creates a new instance of BaseKeys */ 048 public BaseKeys(BaseKey baseKey1, BaseKey baseKey2) { 049 init(baseKey1, baseKey2, null, null); 050 } 051 052 public int getBaseKeyCount() { 053 return (baseKey1 == null ? 0 : 1) + (baseKey2 == null ? 0 : 1) + (baseKey3 == null ? 0 : 1); 054 } 055 056 public BaseKey getBaseKey1() { 057 return baseKey1; 058 } 059 060 public void setBaseKey1(BaseKey baseKey1) { 061 this.baseKey1 = baseKey1; 062 } 063 064 public BaseKey getBaseKey2() { 065 return baseKey2; 066 } 067 068 public void setBaseKey2(BaseKey baseKey2) { 069 this.baseKey2 = baseKey2; 070 } 071 072 public BaseKey getBaseKey3() { 073 return baseKey3; 074 } 075 076 public void setBaseKey3(BaseKey baseKey3) { 077 this.baseKey3 = baseKey3; 078 } 079 080 public String getBaseEncryptionKeyName() { 081 return baseEncryptionKeyName; 082 } 083 084 public void setBaseEncryptionKeyName(String baseEncryptionKeyName) { 085 this.baseEncryptionKeyName = baseEncryptionKeyName; 086 } 087 088 public SecretKey getKey1() { 089 return baseKey1 == null? null: baseKey1.getKey(); 090 } 091 092 public byte[] getIv1() { 093 return baseKey1.getIv(); 094 } 095 096 public SecretKey getKey2() { 097 return baseKey2 == null? null: baseKey2.getKey(); 098 } 099 100 public byte[] getIv2() { 101 return baseKey2.getIv(); 102 } 103 104 public SecretKey getKey3() { 105 return baseKey3 == null? null: baseKey3.getKey(); 106 } 107 108 public byte[] getIv3() { 109 return baseKey3.getIv(); 110 } 111 112}