Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FIT-Connect-SDK - Java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect-SDK - Java
Commits
5d551745
Commit
5d551745
authored
1 year ago
by
Martin Vogel
Browse files
Options
Downloads
Patches
Plain Diff
feat: add test key builder from cli (
planning#667
))
parent
116de61d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!321
Draft: planning#667 Derive VPKI Certs from PKCS KeyStore
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/src/main/java/dev/fitko/fitconnect/tools/jwk/TestKeys.java
+67
-0
67 additions, 0 deletions
...rc/main/java/dev/fitko/fitconnect/tools/jwk/TestKeys.java
with
67 additions
and
0 deletions
tools/src/main/java/dev/fitko/fitconnect/tools/jwk/TestKeys.java
0 → 100644
+
67
−
0
View file @
5d551745
package
dev.fitko.fitconnect.tools.jwk
;
import
com.nimbusds.jose.JWEAlgorithm
;
import
com.nimbusds.jose.JWSAlgorithm
;
import
com.nimbusds.jose.jwk.JWK
;
import
dev.fitko.fitconnect.api.domain.crypto.JWKPair
;
import
dev.fitko.fitconnect.core.crypto.utils.KeyGenerator
;
import
java.security.KeyPair
;
import
java.util.UUID
;
import
static
com
.
nimbusds
.
jose
.
jwk
.
KeyOperation
.
SIGN
;
import
static
com
.
nimbusds
.
jose
.
jwk
.
KeyOperation
.
UNWRAP_KEY
;
import
static
com
.
nimbusds
.
jose
.
jwk
.
KeyOperation
.
VERIFY
;
import
static
com
.
nimbusds
.
jose
.
jwk
.
KeyOperation
.
WRAP_KEY
;
/**
* JWK Test Key Generator.
* <p>
* Generates key pairs of public and private keys for encryption and signing.
*/
public
final
class
TestKeys
{
public
static
final
int
DEFAULT_KEY_SIZE
=
4096
;
private
TestKeys
()
{
}
/**
* Generate a set of public encryption key and private decryption key.
*
* @param keySize size of the RSA key in bits
* @return JWKPair of public and private key
*/
public
static
JWKPair
generateEncryptionKeyPair
(
final
int
keySize
)
{
final
String
keyId
=
UUID
.
randomUUID
().
toString
();
final
JWEAlgorithm
encryptionAlgorithm
=
JWEAlgorithm
.
RSA_OAEP_256
;
final
KeyPair
keyPair
=
KeyGenerator
.
buildRSAKeyPair
(
keySize
);
final
JWK
publicEncryptionKey
=
KeyGenerator
.
buildJWK
(
keyPair
,
keyId
,
WRAP_KEY
,
encryptionAlgorithm
);
final
JWK
privateDecryptionKey
=
KeyGenerator
.
buildJWK
(
keyPair
,
keyId
,
UNWRAP_KEY
,
encryptionAlgorithm
);
return
new
JWKPair
(
publicEncryptionKey
.
toPublicJWK
(),
privateDecryptionKey
);
}
/**
* Generate a set of public signature verification key and private signature key.
*
* @param keySize size of the RSA key in bits
* @return JWKPair of signature and verification key
*/
public
static
JWKPair
generateSignatureKeyPair
(
final
int
keySize
)
{
final
String
keyId
=
UUID
.
randomUUID
().
toString
();
final
JWSAlgorithm
signingAlgorithm
=
JWSAlgorithm
.
PS512
;
final
KeyPair
keyPair
=
KeyGenerator
.
buildRSAKeyPair
(
keySize
);
final
JWK
publicSignatureVerificationKey
=
KeyGenerator
.
buildJWK
(
keyPair
,
keyId
,
VERIFY
,
signingAlgorithm
);
final
JWK
privateSignatureKey
=
KeyGenerator
.
buildJWK
(
keyPair
,
keyId
,
SIGN
,
signingAlgorithm
);
return
new
JWKPair
(
publicSignatureVerificationKey
.
toPublicJWK
(),
privateSignatureKey
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment