public class EncryptionUtils extends Object
| Constructor and Description |
|---|
EncryptionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canUseEncryption()
Check whether java supports the encryption required to authenticate sessions.
|
static com.nimbusds.jose.JWSObject |
createHandshakeJwt(KeyPair serverKeyPair,
byte[] token)
Create handshake JWS used in the
ServerToClientHandshakePacket
which completes the encryption handshake. |
static KeyPair |
createKeyPair()
Create EC key pair to be used for handshake and encryption
|
static ECPublicKey |
generateKey(String b64)
Generate EC public key from base 64 encoded string
|
static byte[] |
generateRandomToken()
Generate 16 bytes of random data for the handshake token using a
SecureRandom |
static ECPublicKey |
getMojangPublicKey()
Mojang's public key used to verify the JWT during login.
|
static SecretKey |
getSecretKey(PrivateKey localPrivateKey,
PublicKey remotePublicKey,
byte[] token)
Generate the secret key used to encrypt the connection
|
static void |
signJwt(com.nimbusds.jose.JWSObject jws,
ECPrivateKey key)
Sign JWS object with a given private key.
|
static boolean |
verifyChain(net.minidev.json.JSONArray chain)
Verify the validity of the login chain data from the
LoginPacket |
static boolean |
verifyJwt(com.nimbusds.jose.JWSObject jws,
ECPublicKey key)
Check whether a JWS object is valid for a given public key.
|
public static ECPublicKey generateKey(String b64) throws NoSuchAlgorithmException, InvalidKeySpecException
b64 - base 64 encoded keyNoSuchAlgorithmException - runtime does not support the EC key specInvalidKeySpecException - input does not conform with EC key specpublic static KeyPair createKeyPair()
public static void signJwt(com.nimbusds.jose.JWSObject jws,
ECPrivateKey key)
throws com.nimbusds.jose.JOSEException
jws - object to be signedkey - key to sign object withcom.nimbusds.jose.JOSEException - invalid key providedpublic static boolean verifyJwt(com.nimbusds.jose.JWSObject jws,
ECPublicKey key)
throws com.nimbusds.jose.JOSEException
jws - object to be verifiedkey - key to verify object withcom.nimbusds.jose.JOSEException - invalid key providedpublic static boolean verifyChain(net.minidev.json.JSONArray chain)
throws com.nimbusds.jose.JOSEException,
ParseException,
InvalidKeySpecException,
NoSuchAlgorithmException
LoginPacketchain - array of JWS objectscom.nimbusds.jose.JOSEException - invalid JWS algorithm usedParseException - invalid JWS objectInvalidKeySpecException - invalid EC key providedNoSuchAlgorithmException - runtime does not support EC specpublic static SecretKey getSecretKey(PrivateKey localPrivateKey, PublicKey remotePublicKey, byte[] token) throws InvalidKeyException
localPrivateKey - local private keyremotePublicKey - remote public keytoken - token generated or received from the serverInvalidKeyException - keys provided are not EC specpublic static com.nimbusds.jose.JWSObject createHandshakeJwt(KeyPair serverKeyPair, byte[] token) throws com.nimbusds.jose.JOSEException
ServerToClientHandshakePacket
which completes the encryption handshake.serverKeyPair - used to sign the JWTtoken - salt for the encryption handshakecom.nimbusds.jose.JOSEException - invalid key pair providedpublic static byte[] generateRandomToken()
SecureRandompublic static boolean canUseEncryption()
public static ECPublicKey getMojangPublicKey()
Copyright © 2018–2019 NukkitX. All rights reserved.