gistfile1.java
· 692 B · Java
Raw
public class OidcClientSecretGenerator {
public static String generateClientSecret() throws NoSuchAlgorithmException {
// 使用 HmacSHA256 算法生成 256 位密钥
KeyGenerator kg = KeyGenerator.getInstance("HmacSHA256");
kg.init(256); // 密钥长度需符合安全要求 [[4]](https://example.com/4 )
SecretKey secretKey = kg.generateKey();
return Base64.getEncoder().encodeToString(secretKey.getEncoded());
}
public static void main(String[] args) {
try {
System.out.println("生成的客户端密钥: " + generateClientSecret());
} catch (Exception e) {
e.printStackTrace();
}
}
}
| 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 | } |