BrightSide Workbench Full Report + Source Code
org.turro.push.security.ServerKeys Class Reference

Static Public Member Functions

static String publicKey ()
 
static String privateKey ()
 
static byte[] encode (ECPublicKey publicKey)
 
static byte[] encode (ECPrivateKey privateKey)
 
static boolean verifyKeyPair (PrivateKey privateKey, PublicKey publicKey)
 
static PrivateKey loadPrivateKey (String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
 
static PrivateKey loadPrivateKey (byte[] decodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
 
static PublicKey loadPublicKey (String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
 
static PublicKey loadPublicKey (byte[] decodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
 

Static Public Attributes

static final String CURVE = "prime256v1"
 
static final String ALGORITHM = "ECDH"
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 58 of file ServerKeys.java.

Member Function Documentation

◆ encode() [1/2]

static byte [] org.turro.push.security.ServerKeys.encode ( ECPrivateKey  privateKey)
static

Definition at line 137 of file ServerKeys.java.

137  {
138  return privateKey.getD().toByteArray();
139  }
Here is the call graph for this function:

◆ encode() [2/2]

static byte [] org.turro.push.security.ServerKeys.encode ( ECPublicKey  publicKey)
static

Definition at line 133 of file ServerKeys.java.

133  {
134  return publicKey.getQ().getEncoded(false);
135  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPrivateKey() [1/2]

static PrivateKey org.turro.push.security.ServerKeys.loadPrivateKey ( byte[]  decodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
static

Definition at line 154 of file ServerKeys.java.

154  {
155  BigInteger s = BigIntegers.fromUnsignedByteArray(decodedPrivateKey);
156  ECParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE);
157  ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(s, parameterSpec);
158  KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, BouncyCastleProvider.PROVIDER_NAME);
159 
160  return keyFactory.generatePrivate(privateKeySpec);
161  }

◆ loadPrivateKey() [2/2]

static PrivateKey org.turro.push.security.ServerKeys.loadPrivateKey ( String  encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
static

Definition at line 149 of file ServerKeys.java.

149  {
150  byte[] decodedPrivateKey = Base64.decodeBase64(encodedPrivateKey);
151  return loadPrivateKey(decodedPrivateKey);
152  }
static PrivateKey loadPrivateKey(String encodedPrivateKey)

◆ loadPublicKey() [1/2]

static PublicKey org.turro.push.security.ServerKeys.loadPublicKey ( byte[]  decodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
static

Definition at line 168 of file ServerKeys.java.

168  {
169  KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, BouncyCastleProvider.PROVIDER_NAME);
170  ECParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(CURVE);
171  ECCurve curve = parameterSpec.getCurve();
172  ECPoint point = curve.decodePoint(decodedPublicKey);
173  ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, parameterSpec);
174 
175  return keyFactory.generatePublic(pubSpec);
176  }

◆ loadPublicKey() [2/2]

static PublicKey org.turro.push.security.ServerKeys.loadPublicKey ( String  encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException
static

Definition at line 163 of file ServerKeys.java.

163  {
164  byte[] decodedPublicKey = Base64.decodeBase64(encodedPublicKey);
165  return loadPublicKey(decodedPublicKey);
166  }
static PublicKey loadPublicKey(String encodedPublicKey)
Here is the caller graph for this function:

◆ privateKey()

static String org.turro.push.security.ServerKeys.privateKey ( )
static

Definition at line 64 of file ServerKeys.java.

64  {
65  return instance().getProperty("sk");
66  }
Here is the caller graph for this function:

◆ publicKey()

static String org.turro.push.security.ServerKeys.publicKey ( )
static

Definition at line 60 of file ServerKeys.java.

60  {
61  return instance().getProperty("pk");
62  }
Here is the caller graph for this function:

◆ verifyKeyPair()

static boolean org.turro.push.security.ServerKeys.verifyKeyPair ( PrivateKey  privateKey,
PublicKey  publicKey 
)
static

Definition at line 141 of file ServerKeys.java.

141  {
142  ECNamedCurveParameterSpec curveParameters = ECNamedCurveTable.getParameterSpec(CURVE);
143  ECPoint g = curveParameters.getG();
144  ECPoint sG = g.multiply(((java.security.interfaces.ECPrivateKey) privateKey).getS());
145 
146  return sG.equals(((ECPublicKey) publicKey).getQ());
147  }
Here is the call graph for this function:

Member Data Documentation

◆ ALGORITHM

final String org.turro.push.security.ServerKeys.ALGORITHM = "ECDH"
static

Definition at line 131 of file ServerKeys.java.

◆ CURVE

final String org.turro.push.security.ServerKeys.CURVE = "prime256v1"
static

Definition at line 130 of file ServerKeys.java.


The documentation for this class was generated from the following file: