use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nhin-d by DirectProject.
the class RESTSmtpAgentConfigFunctional_Test method addCertificatesToLdap.
protected void addCertificatesToLdap(String[] filename, String email) throws Exception {
Entry entry = new Entry();
entry.addAttribute("objectClass", "organizationalUnit");
entry.addAttribute("objectClass", "top");
entry.addAttribute("objectClass", "userPrivKey");
entry.addAttribute("email", email);
for (int i = 0; i < filename.length; i++) {
byte[] buffer = loadCertificateData(filename[i]);
Base64 base64 = new Base64();
String certificateValue = new String(base64.encode(buffer));
entry.addAttribute("privKeyStore", certificateValue);
}
String ou;
int index = email.indexOf("@");
if (index > -1)
ou = email.substring(0, email.indexOf("@"));
else
ou = email;
entry.addAttribute("ou", ou);
rootDSE.createSubcontext("ou=" + ou + ", ou=privKeys, ou=cerner, ou=com, cn=lookupTest", entry.getAttributes());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nhin-d by DirectProject.
the class WSSmtpAgentConfigFunctional_Test method addCertificatesToLdap.
protected void addCertificatesToLdap(String[] filename, String email) throws Exception {
Entry entry = new Entry();
entry.addAttribute("objectClass", "organizationalUnit");
entry.addAttribute("objectClass", "top");
entry.addAttribute("objectClass", "userPrivKey");
entry.addAttribute("email", email);
for (int i = 0; i < filename.length; i++) {
byte[] buffer = loadCertificateData(filename[i]);
Base64 base64 = new Base64();
String certificateValue = new String(base64.encode(buffer));
entry.addAttribute("privKeyStore", certificateValue);
}
String ou;
int index = email.indexOf("@");
if (index > -1)
ou = email.substring(0, email.indexOf("@"));
else
ou = email;
entry.addAttribute("ou", ou);
rootDSE.createSubcontext("ou=" + ou + ", ou=privKeys, ou=cerner, ou=com, cn=lookupTest", entry.getAttributes());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nhin-d by DirectProject.
the class XMLSmtpAgentConfigFunctional_Test method addCertificatesToLdap.
protected void addCertificatesToLdap(String[] filename, String email) throws NamingException {
Entry entry = new Entry();
entry.addAttribute("objectClass", "organizationalUnit");
entry.addAttribute("objectClass", "top");
entry.addAttribute("objectClass", "userPrivKey");
entry.addAttribute("email", email);
File fl = new File("testfile");
int idx = fl.getAbsolutePath().lastIndexOf("testfile");
String path = fl.getAbsolutePath().substring(0, idx);
for (int i = 0; i < filename.length; i++) {
byte[] buffer = new byte[(int) new File(path + "src/test/resources/" + filename[i]).length() + 100];
try {
InputStream stream = TestUtils.class.getResourceAsStream(filename[i]);
stream.read(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Base64 base64 = new Base64();
String certificateValue = new String(base64.encode(buffer));
entry.addAttribute("privKeyStore", certificateValue);
}
String ou = email.substring(0, email.indexOf("@"));
entry.addAttribute("ou", ou);
rootDSE.createSubcontext("ou=" + ou + ", ou=privKeys, ou=cerner, ou=com, cn=lookupTest", entry.getAttributes());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nhin-d by DirectProject.
the class LDAPResearchTest method createLdapEntries.
protected void createLdapEntries() throws NamingException {
/*Attributes attrs = new BasicAttributes( "objectClass", "top", true);
attrs.put("objectClass", "organizationalUnit");
attrs.put("objectClass", "userPrivKey");
attrs.put("email", "gm2552@cerner.com");
attrs.put("privKeyStore", "1234567");
rootDSE.createSubcontext("ou=gm2552, ou=privKeys, ou=cerner, ou=com, cn=lookupTest", attrs);
*/
Entry entry = new Entry();
entry.addAttribute("objectClass", "organizationalUnit");
entry.addAttribute("objectClass", "top");
entry.addAttribute("objectClass", "userPrivKey");
entry.addAttribute("email", "gm2552@cerner.com");
File fl = new File("testfile");
int idx = fl.getAbsolutePath().lastIndexOf("testfile");
String path = fl.getAbsolutePath().substring(0, idx);
byte[] buffer = new byte[(int) new File(path + "src/test/resources/certs/bob.der").length() + 100];
try {
InputStream stream = LDAPResearchTest.class.getClassLoader().getResourceAsStream("certs/bob.der");
stream.read(buffer);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Base64 base64 = new Base64();
String certificateValue = new String(base64.encode(buffer));
entry.addAttribute("privKeyStore", certificateValue);
entry.addAttribute("ou", "gm2552");
rootDSE.createSubcontext("ou=gm2552, ou=privKeys, ou=cerner, ou=com, cn=lookupTest", entry.getAttributes());
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project OpenAttestation by OpenAttestation.
the class TAHelper method getPemPublicKey.
public static PublicKey getPemPublicKey(String filename) {
File f = new File(filename);
FileInputStream filestr = null;
PublicKey pubkey = null;
try {
filestr = new FileInputStream(f);
DataInputStream datastr = new DataInputStream(filestr);
byte[] keyBytes = new byte[(int) f.length()];
datastr.readFully(keyBytes);
datastr.close();
String temp = new String(keyBytes);
String publicKeyPEM = temp.replace("-----BEGIN PUBLIC KEY-----\n", "");
publicKeyPEM = publicKeyPEM.replace("-----END PUBLIC KEY-----", "");
Base64 b64 = new Base64();
byte[] decoded = b64.decode(publicKeyPEM);
X509EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
KeyFactory kf = KeyFactory.getInstance("RSA");
kf.generatePublic(spec);
pubkey = kf.generatePublic(spec);
} catch (FileNotFoundException e) {
log.error("Unable to find rsapubkey file, " + e.toString());
} catch (IOException e) {
log.error("Unable to read nonce file");
} catch (NoSuchAlgorithmException e) {
log.error("no such algorithm " + e.toString());
} catch (InvalidKeySpecException e) {
log.error("invalid key is found " + e.toString());
}
return pubkey;
}
Aggregations