-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Pichler
committed
Nov 18, 2022
1 parent
3eace9d
commit 018c16b
Showing
13 changed files
with
503 additions
and
128 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/io/jenkins/plugins/oidc_provider/ECSecretKeyPair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.jenkins.plugins.oidc_provider; | ||
|
||
import hudson.util.Secret; | ||
import java.security.KeyFactory; | ||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
import java.security.PublicKey; | ||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.security.spec.X509EncodedKeySpec; | ||
import java.util.Base64; | ||
|
||
public class ECSecretKeyPair implements SecretKeyPair { | ||
private static final long serialVersionUID = 2448941858110252020L; | ||
|
||
/** | ||
* Encrypted base64 encoding of a private key in {@link PKCS8EncodedKeySpec} | ||
*/ | ||
private final Secret privateKey; | ||
|
||
/** | ||
* Encrypted base64 encoding of a public key in {@link X509EncodedKeySpec} | ||
*/ | ||
private final Secret publicKey; | ||
|
||
public ECSecretKeyPair(KeyPair keyPair) { | ||
this.privateKey = Secret.fromString(Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded())); | ||
this.publicKey = Secret.fromString(Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded())); | ||
} | ||
|
||
@Override | ||
public KeyPair toKeyPair() throws Exception { | ||
KeyFactory keyFactory = KeyFactory.getInstance("EC"); | ||
|
||
PrivateKey priv = keyFactory.generatePrivate( | ||
new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey.getPlainText()))); | ||
|
||
PublicKey pub = keyFactory.generatePublic( | ||
new X509EncodedKeySpec(Base64.getDecoder().decode(publicKey.getPlainText()))); | ||
|
||
return new KeyPair(pub, priv); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.