use of com.liumapp.digitalsign.engine.keystore.service.KeyStoreAdapter in project spring-cloud-digital-sign by SpringForAll.
the class CertificateController method generate.
/**
* generate personal certificate by self .
* @param personalCertPattern params required
* @return String
*/
@RequestMapping("/generate")
public ResponseEntity<?> generate(@RequestBody PersonalCertPattern personalCertPattern) {
try {
Resource resource = Resource.from(keyStoreSavePath + "/" + personalCertPattern.getKeystore());
KeyStoreAdapter keyStoreAdapter = KeyTools.keyStoreFrom(resource, personalCertPattern.getStorepass());
keyStoreAdapter.newKeyPair().keyLength(personalCertPattern.getKeysize()).generateWithCertificate().withValidity(1, ChronoUnit.YEARS).withDistinguishName().commonName(personalCertPattern.getName()).state(personalCertPattern.getCity()).locality(personalCertPattern.getProvince()).country(personalCertPattern.getCountry()).build().createInKeyStore(personalCertPattern.getAlias(), personalCertPattern.getCertPassword());
FileOutputStream out = new FileOutputStream(keyStoreSavePath + "/" + personalCertPattern.getKeystore());
keyStoreAdapter.writeTo(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ResponseEntity.ok("generator done");
}
use of com.liumapp.digitalsign.engine.keystore.service.KeyStoreAdapter in project spring-cloud-digital-sign by SpringForAll.
the class CertificateController method export.
// public String generate (@RequestBody )
@RequestMapping("/export")
public ResponseEntity<?> export(@RequestBody ExporterPattern exporterPattern) {
try {
Resource resource = Resource.from(keyStoreSavePath + "/" + exporterPattern.getKeyStore());
KeyStoreAdapter keyStoreAdapter = KeyTools.keyStoreFrom(resource, exporterPattern.getKeyStorePd());
Certificate certificate = keyStoreAdapter.getCertificate(exporterPattern.getAlias());
FileOutputStream out = new FileOutputStream(exporterPattern.getSavePath() + "/" + exporterPattern.getFileName());
out.write(certificate.getEncoded());
out.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ResponseEntity.ok("export done");
}
Aggregations