001 /* 002 * Cumulus4j - Securing your data in the cloud - http://cumulus4j.org 003 * Copyright (C) 2011 NightLabs Consulting GmbH 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 package org.cumulus4j.store.crypto.keymanager; 019 020 import java.util.Date; 021 022 import org.cumulus4j.crypto.Cipher; 023 024 /** 025 * {@link CryptoCache}-entry wrapping a {@link Cipher} used for secret-key-decryption. 026 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de 027 */ 028 public class CryptoCacheKeyDecrypterEntry 029 { 030 private CryptoCacheKeyEncryptionKeyEntry keyEncryptionKey; 031 032 private String keyEncryptionTransformation; 033 034 private Cipher keyDecryptor; 035 036 private volatile Date lastUsageTimestamp = new Date(); 037 038 /** 039 * Create a new instance. 040 * @param keyEncryptionKey corresponding key-pair-entry. 041 * @param keyEncryptionTransformation the (public-private-key-pair-)transformation used to encrypt the secret keys used for symmetric encryption/decryption of the actual data. 042 * @param keyDecryptor the cipher. 043 */ 044 protected CryptoCacheKeyDecrypterEntry(CryptoCacheKeyEncryptionKeyEntry keyEncryptionKey, String keyEncryptionTransformation, Cipher keyDecryptor) 045 { 046 if (keyEncryptionKey == null) 047 throw new IllegalArgumentException("keyEncryptionKey == null"); 048 049 if (keyEncryptionTransformation == null) 050 throw new IllegalArgumentException("keyEncryptionTransformation == null"); 051 052 if (keyDecryptor == null) 053 throw new IllegalArgumentException("keyDecryptor == null"); 054 055 this.keyEncryptionKey = keyEncryptionKey; 056 this.keyEncryptionTransformation = keyEncryptionTransformation; 057 this.keyDecryptor = keyDecryptor; 058 } 059 060 public CryptoCacheKeyEncryptionKeyEntry getKeyEncryptionKey() { 061 return keyEncryptionKey; 062 } 063 064 /** 065 * Get the (public-private-key-pair-)transformation used to encrypt the secret keys used for symmetric en-/decryption 066 * of the actual data. 067 * @return the (public-private-key-pair-)transformation used to encrypt the secret keys used for symmetric en-/decryption 068 * of the actual data. 069 */ 070 public String getKeyEncryptionTransformation() { 071 return keyEncryptionTransformation; 072 } 073 074 /** 075 * Get the cipher. 076 * @return the cipher. 077 */ 078 public Cipher getKeyDecryptor() { 079 return keyDecryptor; 080 } 081 082 /** 083 * Get the timestamp when the cipher was used the last time. 084 * @return the timestamp when the cipher was used the last time. 085 */ 086 public Date getLastUsageTimestamp() { 087 return lastUsageTimestamp; 088 } 089 090 /** 091 * Update the {@link #getLastUsageTimestamp() lastUsageTimestamp} (set it to NOW). 092 */ 093 public void updateLastUsageTimestamp() { 094 this.lastUsageTimestamp = new Date(); 095 } 096 }