keycloak
クラス | 静的公開メンバ関数 | 静的関数 | 全メンバ一覧
org.keycloak.common.util.KeystoreUtil クラス
org.keycloak.common.util.KeystoreUtil 連携図
Collaboration graph

クラス

enum  KeystoreFormat
 

静的公開メンバ関数

static KeyStore loadKeyStore (String filename, String password) throws Exception
 
static KeyPair loadKeyPairFromKeystore (String keystoreFile, String storePassword, String keyPassword, String keyAlias, KeystoreFormat format)
 

静的関数

 [static initializer]
 

詳解

著者
Bill Burke
バージョン
Revision
1

クラス詳解

◆ org::keycloak::common::util::KeystoreUtil::KeystoreFormat

enum org::keycloak::common::util::KeystoreUtil::KeystoreFormat
org.keycloak.common.util.KeystoreUtil.KeystoreFormat 連携図
Collaboration graph
列挙値
JKS
PKCS12

関数詳解

◆ [static initializer]()

org.keycloak.common.util.KeystoreUtil.[static initializer] ( )
inlinestaticpackage

◆ loadKeyPairFromKeystore()

static KeyPair org.keycloak.common.util.KeystoreUtil.loadKeyPairFromKeystore ( String  keystoreFile,
String  storePassword,
String  keyPassword,
String  keyAlias,
KeystoreFormat  format 
)
inlinestatic
66  {
67  InputStream stream = FindFile.findFile(keystoreFile);
68 
69  try {
70  KeyStore keyStore = null;
71  if (format == KeystoreFormat.JKS) {
72  keyStore = KeyStore.getInstance(format.toString());
73  } else {
74  keyStore = KeyStore.getInstance(format.toString(), "BC");
75  }
76 
77  keyStore.load(stream, storePassword.toCharArray());
78  PrivateKey privateKey = (PrivateKey) keyStore.getKey(keyAlias, keyPassword.toCharArray());
79  if (privateKey == null) {
80  throw new RuntimeException("Couldn't load key with alias '" + keyAlias + "' from keystore");
81  }
82  PublicKey publicKey = keyStore.getCertificate(keyAlias).getPublicKey();
83  return new KeyPair(publicKey, privateKey);
84  } catch (Exception e) {
85  throw new RuntimeException("Failed to load private key: " + e.getMessage(), e);
86  }
87  }

◆ loadKeyStore()

static KeyStore org.keycloak.common.util.KeystoreUtil.loadKeyStore ( String  filename,
String  password 
) throws Exception
inlinestatic
44  {
45  KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
46  InputStream trustStream = null;
47  if (filename.startsWith(GenericConstants.PROTOCOL_CLASSPATH)) {
48  String resourcePath = filename.replace(GenericConstants.PROTOCOL_CLASSPATH, "");
49  if (Thread.currentThread().getContextClassLoader() != null) {
50  trustStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
51  }
52  if (trustStream == null) {
53  trustStream = KeystoreUtil.class.getResourceAsStream(resourcePath);
54  }
55  if (trustStream == null) {
56  throw new RuntimeException("Unable to find key store in classpath");
57  }
58  } else {
59  trustStream = new FileInputStream(new File(filename));
60  }
61  trustStore.load(trustStream, password.toCharArray());
62  trustStream.close();
63  return trustStore;
64  }

このクラス詳解は次のファイルから抽出されました: