Расшифровка TLS

This commit is contained in:
serega6531
2020-04-23 22:40:27 +03:00
parent e019ade85d
commit 0e460011c2
4 changed files with 131 additions and 35 deletions

View File

@@ -0,0 +1,35 @@
package ru.serega6531.packmate.service.optimization;
import org.springframework.stereotype.Service;
import ru.serega6531.packmate.utils.TlsUtils;
import javax.net.ssl.X509KeyManager;
import java.io.File;
import java.math.BigInteger;
import java.security.interfaces.RSAPrivateKey;
import java.util.HashMap;
import java.util.Map;
@Service
public class RsaKeysHolder {
// Key: N from RSA public key
private final Map<BigInteger, RSAPrivateKey> keys = new HashMap<>();
public void addKey(File pemFile, File keyFile) {
if(!pemFile.exists() || !keyFile.exists()) {
throw new IllegalArgumentException("One of files does not exist");
}
X509KeyManager keyManager = TlsUtils.createKeyManager(pemFile, keyFile);
// X509Certificate[] certificateChain = keyManager.getCertificateChain("1");
RSAPrivateKey privateKey = ((RSAPrivateKey) keyManager.getPrivateKey("1"));
keys.put(privateKey.getModulus(), privateKey);
}
public RSAPrivateKey getKey(BigInteger modulus) {
return keys.get(modulus);
}
}