Search in sources :

Example 1 with KeyStoreAdapter

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");
}
Also used : KeyStoreAdapter(com.liumapp.digitalsign.engine.keystore.service.KeyStoreAdapter) FileOutputStream(java.io.FileOutputStream) Resource(com.liumapp.digitalsign.engine.keystore.entity.Resource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with KeyStoreAdapter

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");
}
Also used : KeyStoreAdapter(com.liumapp.digitalsign.engine.keystore.service.KeyStoreAdapter) FileOutputStream(java.io.FileOutputStream) Resource(com.liumapp.digitalsign.engine.keystore.entity.Resource) Certificate(java.security.cert.Certificate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Resource (com.liumapp.digitalsign.engine.keystore.entity.Resource)2 KeyStoreAdapter (com.liumapp.digitalsign.engine.keystore.service.KeyStoreAdapter)2 FileOutputStream (java.io.FileOutputStream)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Certificate (java.security.cert.Certificate)1