feat:jwt授权
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
<parent>
|
||||
<groupId>com.xiang</groupId>
|
||||
<artifactId>xservice-basic</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<version>1.3</version>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
|
||||
<artifactId>xservice-common</artifactId>
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.xiang.xservice.basic.utils;
|
||||
|
||||
import com.nimbusds.jose.jwk.RSAKey;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JwkUtils {
|
||||
|
||||
|
||||
public static RSAKey generateRsa() {
|
||||
KeyPair keyPair = generateRsaKey();
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
|
||||
return new RSAKey.Builder(publicKey)
|
||||
.privateKey(privateKey)
|
||||
.keyID(UUID.randomUUID().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
static KeyPair generateRsaKey() {
|
||||
KeyPair keyPair;
|
||||
try {
|
||||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
||||
keyPairGenerator.initialize(2048);
|
||||
keyPair = keyPairGenerator.generateKeyPair();
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return keyPair;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user