use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.
the class KMIPGetCustomAttribute method printCustomAttribute.
private static void printCustomAttribute(KMIPAttributes returnedAttributes) {
for (Attribute a : returnedAttributes.attributes) {
if (a.getAttributeName().getCustomName() != null) {
System.out.println("CustomAttribute: " + a.getAttributeName().getCustomName() + " " + a.getAttributeIndex().getAttributeIndex() + " " + returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()));
String customDataTypes = returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()).toString();
if (customDataTypes.equals("TextString"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeTextString(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("DateTime"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeCalendar(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()).getTimeInMillis());
else if (customDataTypes.equals("Integer"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("Boolean"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBoolean(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
}
}
}
use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.
the class KMIPLocateSample method main.
public static void main(String[] args) throws Exception {
if (args.length < 2) {
usage();
}
// add Ingrian provider to the list of JCE providers
Security.addProvider(new IngrianProvider());
KMIPSession session = null;
try {
// create NAE Session: pass in NAE Client Certificate clicnt key and keystore password
session = KMIPSession.getSession(new NAEClientCertificate(args[0], args[1].toCharArray()));
// This set holds the managed object unique identifiers (UIDs)
Set<String> managedObjectIdentifiers;
// Locate keys with crypto algorithm = aes and crypto length = 256
KMIPAttributes queryAttributes = new KMIPAttributes();
/*
* IMPORTANT-In case of locate by name it is compulsory to pass argument for keyName as below
* [-Name locateKeyName] where locateKeyName will be value of userInput.
* */
if (args.length > 3) {
if (args[2] != null && "-Name".equals(args[2])) {
queryAttributes.add(new Attribute(KMIPAttribute.Name, args[3]));
}
}
// Have the session locate the keys matching the queryAttributes:
managedObjectIdentifiers = session.locate(queryAttributes);
// loop through the UIDs of the matching managed objects
System.out.println("Total Keys: " + managedObjectIdentifiers.size());
for (String uid : managedObjectIdentifiers) {
System.out.println("Managed object Unique Identifier: " + uid);
// get the objects as Java client NAEKeys or KMIPSecretData objects
// (Note: Secret Data doesn't have KMIP attributes of
// algorithm or length, and will not be found by this query,
// but is included here for completeness.
byte[] keyMaterial = null;
Object managedObject = session.getManagedObject(uid);
// not a key
if (managedObject == null)
continue;
if (managedObject instanceof NAEPublicKey) {
System.out.println(((NAEPublicKey) managedObject).getName());
keyMaterial = ((NAEKey) managedObject).export();
} else if (managedObject instanceof NAEPrivateKey) {
System.out.println(((NAEPrivateKey) managedObject).getName());
keyMaterial = ((NAEKey) managedObject).export();
} else if (managedObject instanceof NAESecretKey) {
System.out.println(((NAESecretKey) managedObject).getName());
keyMaterial = ((NAEKey) managedObject).export();
} else if (managedObject instanceof KMIPSecretData) {
System.out.println(((KMIPSecretData) managedObject).getName());
keyMaterial = ((KMIPSecretData) managedObject).export();
} else if (managedObject instanceof NAECertificate) {
System.out.println(((NAECertificate) managedObject).getName());
keyMaterial = ((NAECertificate) managedObject).certificateExport();
}
System.out.println("Key Material = " + TTLVUtil.toHexString(keyMaterial));
}
} catch (Exception e) {
System.out.println("The Cause is " + e.getMessage() + ".");
e.printStackTrace();
} finally {
if (session != null)
session.closeSession();
}
}
use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.
the class KMIPSecretDataGetCustomAttributeSample method printCustomAttribute.
private static void printCustomAttribute(KMIPAttributes returnedAttributes) {
for (Attribute a : returnedAttributes.attributes) {
if (a.getAttributeName().getCustomName() != null) {
System.out.println("CustomAttribute: " + a.getAttributeName().getCustomName() + " " + a.getAttributeIndex().getAttributeIndex() + " " + returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()));
String customDataTypes = returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()).toString();
if (customDataTypes.equals("TextString"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeTextString(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("DateTime"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeCalendar(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()).getTimeInMillis());
else if (customDataTypes.equals("Integer"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("Interval"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("Boolean"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBoolean(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
else if (customDataTypes.equals("BigInteger"))
System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBigInteger(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
}
}
}
Aggregations