org.keyczar.ImportedKeyReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of keyczar Show documentation
Show all versions of keyczar Show documentation
Keyczar is a toolkit to make cryptography safer and easier
The newest version!
package org.keyczar;
import org.keyczar.annotations.Experimental;
import org.keyczar.enums.KeyPurpose;
import org.keyczar.enums.KeyStatus;
import org.keyczar.exceptions.KeyczarException;
import org.keyczar.interfaces.KeyczarReader;
import java.util.ArrayList;
import java.util.List;
@Experimental
public class ImportedKeyReader implements KeyczarReader {
private final KeyMetadata metadata;
private final List keys;
ImportedKeyReader(KeyMetadata metadata, List keys) {
this.metadata = metadata;
this.keys = keys;
}
ImportedKeyReader(AesKey key) {
this.metadata = new KeyMetadata(
"Imported AES", KeyPurpose.DECRYPT_AND_ENCRYPT, DefaultKeyType.AES);
KeyVersion version = new KeyVersion(0, KeyStatus.PRIMARY, false);
this.metadata.addVersion(version);
this.keys = new ArrayList();
this.keys.add(key);
}
ImportedKeyReader(HmacKey key) {
this.metadata = new KeyMetadata(
"Imported HMAC", KeyPurpose.SIGN_AND_VERIFY, DefaultKeyType.HMAC_SHA1);
KeyVersion version = new KeyVersion(0, KeyStatus.PRIMARY, false);
this.metadata.addVersion(version);
this.keys = new ArrayList();
this.keys.add(key);
}
@Override
public String getKey() throws KeyczarException {
KeyMetadata metadata = KeyMetadata.read(getMetadata());
return getKey(metadata.getPrimaryVersion().getVersionNumber());
}
@Override
public String getKey(int version) {
return keys.get(version).toString();
}
@Override
public String getMetadata() {
return metadata.toString();
}
}