-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDefaultPrivateKeyProvider.java
More file actions
47 lines (39 loc) · 1.3 KB
/
DefaultPrivateKeyProvider.java
File metadata and controls
47 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.safeheron.client;
import com.safeheron.client.config.RSATypeEnum;
import com.safeheron.client.utils.RsaUtil;
import java.util.Objects;
/**
* Built-in default KeyProvider implementation that uses a local RSA private key.
*
* @author Jiahj
*/
public final class DefaultPrivateKeyProvider implements KeyProvider {
private final String privateKey;
public DefaultPrivateKeyProvider(String privateKey) {
this.privateKey = Objects.requireNonNull(privateKey, "privateKey must not be null");
}
@Override
public String sign(String content) {
try {
return RsaUtil.sign(content, privateKey);
} catch (Exception e) {
throw new RuntimeException("Failed to sign content with RSA", e);
}
}
@Override
public String signPSS(String content) {
try {
return RsaUtil.signPSS(content, privateKey);
} catch (Exception e) {
throw new RuntimeException("Failed to sign content with RSA-PSS", e);
}
}
@Override
public byte[] decrypt(String content, RSATypeEnum rsaType) {
try {
return RsaUtil.decrypt(content, privateKey, rsaType);
} catch (Exception e) {
throw new RuntimeException("Failed to decrypt content with RSA", e);
}
}
}