@@ -38,16 +38,18 @@ class CsrHelper {
38
38
*
39
39
* @param keyPair the KeyPair with private and public keys
40
40
* @param userId userId of CSR owner
41
+ * @param algorithm represents supported signature algorithm
41
42
* @return PEM encoded CSR string
42
43
* @throws IOException thrown if key cannot be created
43
44
* @throws OperatorCreationException thrown if contentSigner cannot be build
44
45
*/
45
46
@Throws(IOException ::class , OperatorCreationException ::class )
46
47
fun generateCsrPemEncodedString (
47
48
keyPair : KeyPair ,
48
- userId : String
49
+ userId : String ,
50
+ algorithm : SignatureAlgorithm
49
51
): String {
50
- val csr = generateCSR(keyPair, userId)
52
+ val csr = generateCSR(keyPair, userId, algorithm )
51
53
val derCSR = csr.encoded
52
54
return " -----BEGIN CERTIFICATE REQUEST-----\n " +
53
55
Base64 .encodeToString(
@@ -61,6 +63,7 @@ class CsrHelper {
61
63
*
62
64
* @param keyPair the KeyPair with private and public keys
63
65
* @param userId userId of CSR owner
66
+ * @param algorithm represents supported signature algorithm
64
67
* @return PKCS10CertificationRequest with the certificate signing request (CSR) data
65
68
* @throws IOException thrown if key cannot be created
66
69
* @throws OperatorCreationException thrown if contentSigner cannot be build
@@ -69,12 +72,13 @@ class CsrHelper {
69
72
@Throws(IOException ::class , OperatorCreationException ::class )
70
73
private fun generateCSR (
71
74
keyPair : KeyPair ,
72
- userId : String
75
+ userId : String ,
76
+ algorithm : SignatureAlgorithm
73
77
): PKCS10CertificationRequest {
74
78
val principal = " CN=$userId "
75
79
val privateKey = PrivateKeyFactory .createKey(keyPair.private.encoded)
76
- val signatureAlgorithm = DefaultSignatureAlgorithmIdentifierFinder ().find(" SHA1WITHRSA " )
77
- val digestAlgorithm = DefaultDigestAlgorithmIdentifierFinder ().find(" SHA-1 " )
80
+ val signatureAlgorithm = DefaultSignatureAlgorithmIdentifierFinder ().find(algorithm.signatureAlg )
81
+ val digestAlgorithm = DefaultDigestAlgorithmIdentifierFinder ().find(algorithm.digestAlg )
78
82
val signer =
79
83
BcRSAContentSignerBuilder (signatureAlgorithm, digestAlgorithm).build(privateKey)
80
84
val csrBuilder: PKCS10CertificationRequestBuilder =
0 commit comments