public final class EncryptionUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static javax.crypto.Cipher |
createCipher(boolean gcm,
boolean encrypt,
javax.crypto.SecretKey key) |
static com.nimbusds.jose.JWSObject |
createHandshakeJwt(java.security.KeyPair serverKeyPair,
byte[] token)
Create handshake JWS used in the
ServerToClientHandshakePacket
which completes the encryption handshake. |
static java.security.KeyPair |
createKeyPair()
Create EC key pair to be used for handshake and encryption
|
static java.security.interfaces.ECPublicKey |
generateKey(java.lang.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 java.security.interfaces.ECPublicKey |
getMojangPublicKey()
Mojang's public key used to verify the JWT during login.
|
static javax.crypto.SecretKey |
getSecretKey(java.security.PrivateKey localPrivateKey,
java.security.PublicKey remotePublicKey,
byte[] token)
Generate the secret key used to encrypt the connection
|
static void |
signJwt(com.nimbusds.jose.JWSObject jws,
java.security.interfaces.ECPrivateKey key)
Sign JWS object with a given private key.
|
static boolean |
verifyChain(java.util.List<com.nimbusds.jwt.SignedJWT> chain)
Verify the validity of the login chain data from the
LoginPacket |
static boolean |
verifyJwt(com.nimbusds.jose.JWSObject jws,
java.security.interfaces.ECPublicKey key)
Check whether a JWS object is valid for a given public key.
|
public static java.security.interfaces.ECPublicKey generateKey(java.lang.String b64)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException
b64 - base 64 encoded keyjava.security.NoSuchAlgorithmException - runtime does not support the EC key specjava.security.spec.InvalidKeySpecException - input does not conform with EC key specpublic static java.security.KeyPair createKeyPair()
public static void signJwt(com.nimbusds.jose.JWSObject jws,
java.security.interfaces.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,
java.security.interfaces.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(java.util.List<com.nimbusds.jwt.SignedJWT> chain)
throws com.nimbusds.jose.JOSEException,
java.security.spec.InvalidKeySpecException,
java.security.NoSuchAlgorithmException
LoginPacketchain - array of JWS objectscom.nimbusds.jose.JOSEException - invalid JWS algorithm usedjava.security.spec.InvalidKeySpecException - invalid EC key providedjava.security.NoSuchAlgorithmException - runtime does not support EC specpublic static javax.crypto.SecretKey getSecretKey(java.security.PrivateKey localPrivateKey,
java.security.PublicKey remotePublicKey,
byte[] token)
throws java.security.InvalidKeyException
localPrivateKey - local private keyremotePublicKey - remote public keytoken - token generated or received from the serverjava.security.InvalidKeyException - keys provided are not EC specpublic static com.nimbusds.jose.JWSObject createHandshakeJwt(java.security.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 java.security.interfaces.ECPublicKey getMojangPublicKey()
public static javax.crypto.Cipher createCipher(boolean gcm,
boolean encrypt,
javax.crypto.SecretKey key)