Created
October 24, 2017 03:56
-
-
Save mizanRahman/3e0ac4275acdf7a99c9d8ebec0350e52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface HsmCrypto { | |
public String encrypt(String keyLabel, String data) | |
public String decrypt(String keyLabel, String data) | |
public String sign(String keyLabel, String data) | |
} | |
class HsmCryptoSafenet implements HsmCrypto { | |
private CryptoBo crypto; | |
private HsmCryptoConfig config; | |
HsmCryptoSafenet() { | |
this.crypto = new CryptoBoImpl() | |
tnis.config = new HsmCryptoConfig() | |
} | |
HsmCryptoSafenet(CryptoBo crypto, HsmCryptoConfig config) { | |
this.crypto = crypto; | |
this.config = config; | |
} | |
public String encrypt(String keyLabel, String data) { | |
crypto.encrypt(keyLabel, config.getDefaultSlot(), data) | |
} | |
public String encrypt(String keyLabel, int slot, String data) { | |
crypto.encrypt(keyLabel,slot, data) | |
} | |
public String decrypt(String keyLabel, String data) { | |
crypto.decrypt(keyLabel,data) | |
} | |
public String sign(String keyLabel, String data) { | |
crypto.sign(keyLabel,data) | |
} | |
} | |
@Data | |
@Builder | |
class HsmCryptoConfig { | |
private String libraryPath; | |
private boolean cacheTokenSession; | |
private int defaultSlot; | |
HsmCryptoConfig() { | |
//defaults | |
} | |
HsmCryptoConfig(Properties properties) { | |
// set from properties | |
} | |
HsmCryptoConfig(String pathToPropertiesFile) { | |
// set by reading from properties file | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
core | |
hsm-crypto-api | |
hsm-crypto-safenet | |
hsm-crypto-luna | |
hsm-crypto-thelas | |
application | |
hsm-crypto-cli | |
- ping | |
- health | |
- encrypt | |
- decrypt | |
- sign | |
- verify | |
hsm-crypto-test | |
spring-boot-starter-hsm-crypto | |
### 1 | |
HsmCryptoConfig hsmCryptoConfig = new HsmCryptoConfig() | |
hsmCryptoConfig.setLibraryPath("path/to/crypto.so") | |
hsmCryptoConfig.setDefaultSlot(1) | |
hsmCryptoConfig.setCacheTokenSession(true) | |
HsmCrypto hsmCrypto = new HsmCryptoSafenet(hsmCryptoConfig); | |
### 2 | |
config = HsmCryptoConfig.Builder() | |
.libraryPath("path.to/crypto.so") | |
.defaultSlot(1) | |
.isCacheTokenSession(true) | |
.build(); | |
HsmCrypto hsmCrypto = new HsmCryptoSafenet(config); | |
### 3 | |
HsmCryptoSafenet.Builder() | |
.libraryPath("path.to/crypto.so") | |
.defaultSlot(1) | |
.isCacheTokenSession(true) | |
.cryptoBo | |
.build(); | |
HsmCrypto.build() | |
HsmCrypto | |
.config(HsmCryptoConfig | |
.libraryPath("path/to/lib.so") | |
.defaultSlot(1) | |
.cacheTokenSession(true) | |
.build() | |
.build() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment