use of com.github.zhenwei.core.asn1.bc.ObjectDataSequence in project LinLong-Java by zhenwei1108.
the class ObjectStoreData method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(6);
v.add(new ASN1Integer(version));
v.add(integrityAlgorithm);
v.add(creationDate);
v.add(lastModifiedDate);
v.add(objectDataSequence);
if (comment != null) {
v.add(new DERUTF8String(comment));
}
return new DERSequence(v);
}
use of com.github.zhenwei.core.asn1.bc.ObjectDataSequence in project LinLong-Java by zhenwei1108.
the class BcFKSKeyStoreSpi method getEncryptedObjectStoreData.
private EncryptedObjectStoreData getEncryptedObjectStoreData(AlgorithmIdentifier integrityAlgorithm, char[] password) throws IOException, NoSuchAlgorithmException {
ObjectData[] dataArray = (ObjectData[]) entries.values().toArray(new ObjectData[entries.size()]);
KeyDerivationFunc pbkdAlgId = generatePkbdAlgorithmIdentifier(hmacPkbdAlgorithm, 256 / 8);
byte[] keyBytes = generateKey(pbkdAlgId, "STORE_ENCRYPTION", ((password != null) ? password : new char[0]), 256 / 8);
ObjectStoreData storeData = new ObjectStoreData(integrityAlgorithm, creationDate, lastModifiedDate, new ObjectDataSequence(dataArray), null);
EncryptedObjectStoreData encStoreData;
try {
if (storeEncryptionAlgorithm.equals(NISTObjectIdentifiers.id_aes256_CCM)) {
Cipher c = createCipher("AES/CCM/NoPadding", keyBytes);
byte[] encOut = c.doFinal(storeData.getEncoded());
AlgorithmParameters algorithmParameters = c.getParameters();
PBES2Parameters pbeParams = new PBES2Parameters(pbkdAlgId, new EncryptionScheme(NISTObjectIdentifiers.id_aes256_CCM, CCMParameters.getInstance(algorithmParameters.getEncoded())));
encStoreData = new EncryptedObjectStoreData(new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBES2, pbeParams), encOut);
} else {
Cipher c = createCipher("AESKWP", keyBytes);
byte[] encOut = c.doFinal(storeData.getEncoded());
PBES2Parameters pbeParams = new PBES2Parameters(pbkdAlgId, new EncryptionScheme(NISTObjectIdentifiers.id_aes256_wrap_pad));
encStoreData = new EncryptedObjectStoreData(new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBES2, pbeParams), encOut);
}
} catch (NoSuchPaddingException e) {
throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
throw new IOException(e.toString());
} catch (IllegalBlockSizeException e) {
throw new IOException(e.toString());
} catch (InvalidKeyException e) {
throw new IOException(e.toString());
} catch (NoSuchProviderException e) {
throw new IOException(e.toString());
}
return encStoreData;
}
Aggregations