Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Created October 24, 2017 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizanRahman/3e0ac4275acdf7a99c9d8ebec0350e52 to your computer and use it in GitHub Desktop.
Save mizanRahman/3e0ac4275acdf7a99c9d8ebec0350e52 to your computer and use it in GitHub Desktop.
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
}
}
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