gluu
公開メンバ関数 | 静的公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.xdi.oxauth.model.crypto.signature.RSAKeyFactory クラス
org.xdi.oxauth.model.crypto.signature.RSAKeyFactory の継承関係図
Inheritance graph
org.xdi.oxauth.model.crypto.signature.RSAKeyFactory 連携図
Collaboration graph

公開メンバ関数

 RSAKeyFactory (SignatureAlgorithm signatureAlgorithm, String dnName) throws InvalidParameterException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException, CertificateEncodingException
 
 RSAKeyFactory (JSONWebKey p_key)
 
RSAPrivateKey getPrivateKey ()
 
RSAPublicKey getPublicKey ()
 
Certificate getCertificate ()
 
Key< E, F > getKey ()
 

静的公開メンバ関数

static RSAKeyFactory valueOf (JSONWebKey p_key)
 

非公開変数類

RSAPrivateKey rsaPrivateKey
 
RSAPublicKey rsaPublicKey
 
Certificate certificate
 

詳解

Factory to create asymmetric Public and Private Keys for the RSA algorithm

著者
Javier Rojas Blum
バージョン
June 15, 2016

構築子と解体子

◆ RSAKeyFactory() [1/2]

org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.RSAKeyFactory ( SignatureAlgorithm  signatureAlgorithm,
String  dnName 
) throws InvalidParameterException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException, CertificateEncodingException
inline
42  {
43  if (signatureAlgorithm == null) {
44  throw new InvalidParameterException("The signature algorithm cannot be null");
45  }
46 
47  KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
48  keyGen.initialize(2048, new SecureRandom());
49 
50  KeyPair keyPair = keyGen.generateKeyPair();
51 
52  BCRSAPrivateCrtKey jcersaPrivateCrtKey = (BCRSAPrivateCrtKey) keyPair.getPrivate();
53  BCRSAPublicKey jcersaPublicKey = (BCRSAPublicKey) keyPair.getPublic();
54 
55  rsaPrivateKey = new RSAPrivateKey(jcersaPrivateCrtKey.getModulus(),
56  jcersaPrivateCrtKey.getPrivateExponent());
57 
58  rsaPublicKey = new RSAPublicKey(jcersaPublicKey.getModulus(),
59  jcersaPublicKey.getPublicExponent());
60 
61  if (StringUtils.isNotBlank(dnName)) {
62  // Create certificate
63  GregorianCalendar startDate = new GregorianCalendar(); // time from which certificate is valid
64  GregorianCalendar expiryDate = new GregorianCalendar(); // time after which certificate is not valid
65  expiryDate.add(Calendar.YEAR, 1);
66  BigInteger serialNumber = new BigInteger(1024, new Random()); // serial number for certificate
67 
68  X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
69  X500Principal principal = new X500Principal(dnName);
70 
71  certGen.setSerialNumber(serialNumber);
72  certGen.setIssuerDN(principal);
73  certGen.setNotBefore(startDate.getTime());
74  certGen.setNotAfter(expiryDate.getTime());
75  certGen.setSubjectDN(principal); // note: same as issuer
76  certGen.setPublicKey(keyPair.getPublic());
77  certGen.setSignatureAlgorithm(signatureAlgorithm.getAlgorithm());
78 
79  X509Certificate x509Certificate = certGen.generate(jcersaPrivateCrtKey, "BC");
80  certificate = new Certificate(signatureAlgorithm, x509Certificate);
81  }
82  }
RSAPublicKey rsaPublicKey
Definition: RSAKeyFactory.java:36
Certificate certificate
Definition: RSAKeyFactory.java:37
RSAPrivateKey rsaPrivateKey
Definition: RSAKeyFactory.java:35

◆ RSAKeyFactory() [2/2]

org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.RSAKeyFactory ( JSONWebKey  p_key)
inline
85  {
86  if (p_key == null) {
87  throw new IllegalArgumentException("Key value must not be null.");
88  }
89 
90  rsaPrivateKey = new RSAPrivateKey(
91  p_key.getN(),
92  p_key.getE());
93  rsaPublicKey = new RSAPublicKey(
94  p_key.getN(),
95  p_key.getE());
96  certificate = null;
97  }
RSAPublicKey rsaPublicKey
Definition: RSAKeyFactory.java:36
Certificate certificate
Definition: RSAKeyFactory.java:37
RSAPrivateKey rsaPrivateKey
Definition: RSAKeyFactory.java:35

関数詳解

◆ getCertificate()

Certificate org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.getCertificate ( )
inline
114  {
115  return certificate;
116  }
Certificate certificate
Definition: RSAKeyFactory.java:37

◆ getKey()

Key<E, F> org.xdi.oxauth.model.crypto.KeyFactory< E extends PrivateKey, F extends PublicKey >.getKey ( )
inlineinherited
22  {
23  Key key = new Key();
24 
25  key.setPrivateKey(getPrivateKey());
26  key.setPublicKey(getPublicKey());
27  key.setCertificate(getCertificate());
28 
29  return key;
30  }
abstract Certificate getCertificate()

◆ getPrivateKey()

RSAPrivateKey org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.getPrivateKey ( )
inline
104  {
105  return rsaPrivateKey;
106  }
RSAPrivateKey rsaPrivateKey
Definition: RSAKeyFactory.java:35

◆ getPublicKey()

RSAPublicKey org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.getPublicKey ( )
inline
109  {
110  return rsaPublicKey;
111  }
RSAPublicKey rsaPublicKey
Definition: RSAKeyFactory.java:36

◆ valueOf()

static RSAKeyFactory org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.valueOf ( JSONWebKey  p_key)
inlinestatic
99  {
100  return new RSAKeyFactory(p_key);
101  }
RSAKeyFactory(SignatureAlgorithm signatureAlgorithm, String dnName)
Definition: RSAKeyFactory.java:40

メンバ詳解

◆ certificate

Certificate org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.certificate
private

◆ rsaPrivateKey

RSAPrivateKey org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.rsaPrivateKey
private

◆ rsaPublicKey

RSAPublicKey org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.rsaPublicKey
private

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