public final class EncryptionUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ALGORITHM_TYPE |
| Modifier and Type | Method and Description |
|---|---|
static javax.crypto.Cipher |
createCipher(boolean gcm,
boolean encrypt,
javax.crypto.SecretKey key) |
static java.lang.String |
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 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 java.security.interfaces.ECPublicKey |
parseKey(java.lang.String b64)
Generate EC public key from base 64 encoded string
|
static ChainValidationResult |
validateChain(java.util.List<java.lang.String> chain) |
static byte[] |
verifyClientData(java.lang.String clientDataJwt,
java.security.PublicKey identityPublicKey) |
static byte[] |
verifyClientData(java.lang.String clientDataJwt,
java.lang.String identityPublicKey) |
public static final java.lang.String ALGORITHM_TYPE
public static java.security.interfaces.ECPublicKey parseKey(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 byte[] verifyClientData(java.lang.String clientDataJwt,
java.lang.String identityPublicKey)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException,
org.jose4j.lang.JoseException
java.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionorg.jose4j.lang.JoseExceptionpublic static byte[] verifyClientData(java.lang.String clientDataJwt,
java.security.PublicKey identityPublicKey)
throws org.jose4j.lang.JoseException
org.jose4j.lang.JoseExceptionpublic static ChainValidationResult validateChain(java.util.List<java.lang.String> chain) throws org.jose4j.lang.JoseException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
org.jose4j.lang.JoseExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecExceptionpublic 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 java.lang.String createHandshakeJwt(java.security.KeyPair serverKeyPair,
byte[] token)
throws org.jose4j.lang.JoseException
ServerToClientHandshakePacket
which completes the encryption handshake.serverKeyPair - used to sign the JWTtoken - salt for the encryption handshakeorg.jose4j.lang.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)