xiushen revised this gist . Go to revision
1 file changed, 0 insertions, 0 deletions
gistfile1.txt renamed to gistfile1.java
File renamed without changes
xiushen revised this gist . Go to revision
1 file changed, 17 insertions
gistfile1.txt(file created)
| @@ -0,0 +1,17 @@ | |||
| 1 | + | public class OidcClientSecretGenerator { | |
| 2 | + | public static String generateClientSecret() throws NoSuchAlgorithmException { | |
| 3 | + | // 使用 HmacSHA256 算法生成 256 位密钥 | |
| 4 | + | KeyGenerator kg = KeyGenerator.getInstance("HmacSHA256"); | |
| 5 | + | kg.init(256); // 密钥长度需符合安全要求 [[4]](https://example.com/4 ) | |
| 6 | + | SecretKey secretKey = kg.generateKey(); | |
| 7 | + | return Base64.getEncoder().encodeToString(secretKey.getEncoded()); | |
| 8 | + | } | |
| 9 | + | ||
| 10 | + | public static void main(String[] args) { | |
| 11 | + | try { | |
| 12 | + | System.out.println("生成的客户端密钥: " + generateClientSecret()); | |
| 13 | + | } catch (Exception e) { | |
| 14 | + | e.printStackTrace(); | |
| 15 | + | } | |
| 16 | + | } | |
| 17 | + | } | |