Class NetworkEncryptionUtils
- API Note:
- Methods in this class usually throw
NetworkEncryptionException
when the operation fails. This is a checked exception and thus must be caught when using the methods. - Mappings:
Namespace Name named net/minecraft/network/encryption/NetworkEncryptionUtils
intermediary net/minecraft/class_3515
official axl
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static interface
NetworkEncryptionUtils.KeyDecoder<T extends Key>
A functional interface that decodes an encoded key.static class
Utilities for working with a secure random number generator.static final record
A record holding a signature of a data and the salt added while signing. -
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private static final int
static final Base64.Encoder
private static final String
static final String
private static final String
private static final int
static final com.mojang.serialization.Codec
<PrivateKey> The codec for RSA private keys.private static final String
private static final String
static final com.mojang.serialization.Codec
<PublicKey> The codec for RSA public keys.static final String
private static final String
private static final String
static final int
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cipher
cipherFromKey
(int opMode, Key key) Creates an AES cipher from the key.static byte[]
computeServerId
(String baseServerId, PublicKey publicKey, SecretKey secretKey) Returns the computed server ID.private static Cipher
createCipher
(int opMode, String algorithm, Key key) Creates a cipher to perform encryption or decryption operation.private static byte[]
Low-level API to perform encryption or decryption operation.private static PrivateKey
decodeEncodedRsaPrivateKey
(byte[] key) Decodes a PCKS #8-encoded RSA private key.static PublicKey
decodeEncodedRsaPublicKey
(byte[] key) Decodes a X.509-encoded RSA public key.private static <T extends Key>
TdecodePem
(String key, String prefix, String suffix, NetworkEncryptionUtils.KeyDecoder<T> decoder) Decodes a PEM-formatted string key.static PrivateKey
Decodes a PEM-formatted RSA private key.static PublicKey
Decodes a PEM-formatted RSA public key.static byte[]
Decrypts an encrypted data.static SecretKey
decryptSecretKey
(PrivateKey privateKey, byte[] encryptedSecretKey) Decrypts RSA-encrypted AES secret key.static String
Encodes an RSA privatekey
to a PEM-formatted key string.static String
Encodes an RSA publickey
to a PEM-formatted key string.static byte[]
Encrypts a data.static SecretKey
Returns a new 128 bit AES secret key.static KeyPair
Returns a new 1024 bit RSA public/private key pair.private static byte[]
hash
(byte[][] bytes) Returns the SHA-1 hash ofbytes
.
-
Field Details
-
AES
- See Also:
- Mappings:
Namespace Name Mixin selector named AES
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;AES:Ljava/lang/String;
intermediary field_29830
Lnet/minecraft/class_3515;field_29830:Ljava/lang/String;
official h
Laxl;h:Ljava/lang/String;
-
AES_KEY_LENGTH
private static final int AES_KEY_LENGTH- See Also:
- Mappings:
Namespace Name Mixin selector named AES_KEY_LENGTH
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;AES_KEY_LENGTH:I
intermediary field_29831
Lnet/minecraft/class_3515;field_29831:I
official i
Laxl;i:I
-
RSA
- See Also:
- Mappings:
Namespace Name Mixin selector named RSA
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA:Ljava/lang/String;
intermediary field_29832
Lnet/minecraft/class_3515;field_29832:Ljava/lang/String;
official j
Laxl;j:Ljava/lang/String;
-
RSA_KEY_LENGTH
private static final int RSA_KEY_LENGTH- See Also:
- Mappings:
Namespace Name Mixin selector named RSA_KEY_LENGTH
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_KEY_LENGTH:I
intermediary field_29833
Lnet/minecraft/class_3515;field_29833:I
official k
Laxl;k:I
-
ISO_8859_1
- See Also:
- Mappings:
Namespace Name Mixin selector named ISO_8859_1
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;ISO_8859_1:Ljava/lang/String;
intermediary field_29834
Lnet/minecraft/class_3515;field_29834:Ljava/lang/String;
official l
Laxl;l:Ljava/lang/String;
-
SHA1
- See Also:
- Mappings:
Namespace Name Mixin selector named SHA1
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA1:Ljava/lang/String;
intermediary field_29835
Lnet/minecraft/class_3515;field_29835:Ljava/lang/String;
official m
Laxl;m:Ljava/lang/String;
-
SHA256_WITH_RSA
- See Also:
- Mappings:
Namespace Name Mixin selector named SHA256_WITH_RSA
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_WITH_RSA:Ljava/lang/String;
intermediary field_39109
Lnet/minecraft/class_3515;field_39109:Ljava/lang/String;
official a
Laxl;a:Ljava/lang/String;
-
SHA256_BITS
public static final int SHA256_BITS- See Also:
- Mappings:
Namespace Name Mixin selector named SHA256_BITS
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_BITS:I
intermediary field_40111
Lnet/minecraft/class_3515;field_40111:I
official b
Laxl;b:I
-
RSA_PRIVATE_KEY_PREFIX
- See Also:
- Mappings:
Namespace Name Mixin selector named RSA_PRIVATE_KEY_PREFIX
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_PREFIX:Ljava/lang/String;
intermediary field_39037
Lnet/minecraft/class_3515;field_39037:Ljava/lang/String;
official n
Laxl;n:Ljava/lang/String;
-
RSA_PRIVATE_KEY_SUFFIX
- See Also:
- Mappings:
Namespace Name Mixin selector named RSA_PRIVATE_KEY_SUFFIX
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_SUFFIX:Ljava/lang/String;
intermediary field_39038
Lnet/minecraft/class_3515;field_39038:Ljava/lang/String;
official o
Laxl;o:Ljava/lang/String;
-
RSA_PUBLIC_KEY_PREFIX
- See Also:
- Mappings:
Namespace Name Mixin selector named RSA_PUBLIC_KEY_PREFIX
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_PREFIX:Ljava/lang/String;
intermediary field_39033
Lnet/minecraft/class_3515;field_39033:Ljava/lang/String;
official c
Laxl;c:Ljava/lang/String;
-
RSA_PUBLIC_KEY_SUFFIX
- See Also:
- Mappings:
Namespace Name Mixin selector named RSA_PUBLIC_KEY_SUFFIX
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_SUFFIX:Ljava/lang/String;
intermediary field_39039
Lnet/minecraft/class_3515;field_39039:Ljava/lang/String;
official p
Laxl;p:Ljava/lang/String;
-
LINEBREAK
- See Also:
- Mappings:
Namespace Name Mixin selector named LINEBREAK
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;LINEBREAK:Ljava/lang/String;
intermediary field_39034
Lnet/minecraft/class_3515;field_39034:Ljava/lang/String;
official d
Laxl;d:Ljava/lang/String;
-
BASE64_ENCODER
- Mappings:
Namespace Name Mixin selector named BASE64_ENCODER
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;BASE64_ENCODER:Ljava/util/Base64$Encoder;
intermediary field_39272
Lnet/minecraft/class_3515;field_39272:Ljava/util/Base64$Encoder;
official e
Laxl;e:Ljava/util/Base64$Encoder;
-
RSA_PUBLIC_KEY_CODEC
The codec for RSA public keys.- See Also:
- Implementation Note:
- The key is encoded using the PEM format.
- Mappings:
Namespace Name Mixin selector named RSA_PUBLIC_KEY_CODEC
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_CODEC:Lcom/mojang/serialization/Codec;
intermediary field_39035
Lnet/minecraft/class_3515;field_39035:Lcom/mojang/serialization/Codec;
official f
Laxl;f:Lcom/mojang/serialization/Codec;
-
RSA_PRIVATE_KEY_CODEC
The codec for RSA private keys.- See Also:
- Implementation Note:
- The key is encoded using the PEM format.
- Mappings:
Namespace Name Mixin selector named RSA_PRIVATE_KEY_CODEC
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_CODEC:Lcom/mojang/serialization/Codec;
intermediary field_39036
Lnet/minecraft/class_3515;field_39036:Lcom/mojang/serialization/Codec;
official g
Laxl;g:Lcom/mojang/serialization/Codec;
-
-
Constructor Details
-
NetworkEncryptionUtils
public NetworkEncryptionUtils()
-
-
Method Details
-
generateSecretKey
Returns a new 128 bit AES secret key.- Returns:
- a new 128 bit AES secret key
- Throws:
NetworkEncryptionException
- when generation fails- Mappings:
Namespace Name Mixin selector named generateSecretKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;generateSecretKey()Ljavax/crypto/SecretKey;
intermediary method_15239
Lnet/minecraft/class_3515;method_15239()Ljavax/crypto/SecretKey;
official a
Laxl;a()Ljavax/crypto/SecretKey;
-
generateServerKeyPair
Returns a new 1024 bit RSA public/private key pair.- Returns:
- a new 1024 bit RSA public/private key pair
- Throws:
NetworkEncryptionException
- when generation fails- Mappings:
Namespace Name Mixin selector named generateServerKeyPair
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;generateServerKeyPair()Ljava/security/KeyPair;
intermediary method_15237
Lnet/minecraft/class_3515;method_15237()Ljava/security/KeyPair;
official b
Laxl;b()Ljava/security/KeyPair;
-
computeServerId
public static byte[] computeServerId(String baseServerId, PublicKey publicKey, SecretKey secretKey) throws NetworkEncryptionException Returns the computed server ID.- Returns:
- the computed server ID
- Throws:
NetworkEncryptionException
- when computation fails- Implementation Note:
- The server ID is a SHA-1 hash of ISO-8859-1 encoded
baseServerId
,publicKey
, andsecretKey
. - Mappings:
Namespace Name Mixin selector named computeServerId
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;computeServerId(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[B
intermediary method_15240
Lnet/minecraft/class_3515;method_15240(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[B
official a
Laxl;a(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[B
-
hash
Returns the SHA-1 hash ofbytes
.- Returns:
- the SHA-1 hash of
bytes
- Throws:
Exception
- Mappings:
Namespace Name Mixin selector named hash
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;hash([[B)[B
intermediary method_15236
Lnet/minecraft/class_3515;method_15236([[B)[B
official a
Laxl;a([[B)[B
-
decodePem
private static <T extends Key> T decodePem(String key, String prefix, String suffix, NetworkEncryptionUtils.KeyDecoder<T> decoder) throws NetworkEncryptionException Decodes a PEM-formatted string key.A PEM-formatted key is
prefix
, followed by Base64 encoded key, followed bysuffix
. Note that this method also allows Base64 encoded keys that have neither the prefix or the suffix.- Throws:
NetworkEncryptionException
- when thedecoder
throws, e.g. due to invalid key content- Mappings:
Namespace Name Mixin selector named decodePem
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodePem(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/network/encryption/NetworkEncryptionUtils$KeyDecoder;)Ljava/security/Key;
intermediary method_43520
Lnet/minecraft/class_3515;method_43520(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/class_3515$class_7424;)Ljava/security/Key;
official a
Laxl;a(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Laxl$a;)Ljava/security/Key;
-
decodeRsaPrivateKeyPem
Decodes a PEM-formatted RSA private key.A PEM-formatted RSA private key is "-----BEGIN RSA PRIVATE KEY-----", followed by Base64 encoded PCKS #8 encoded key, followed by "-----END RSA PRIVATE KEY-----". Note that this method also allows Base64 encoded keys that have neither the prefix or the suffix.
- Throws:
NetworkEncryptionException
- when the key is malformed- See Also:
- Mappings:
Namespace Name Mixin selector named decodeRsaPrivateKeyPem
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPrivateKeyPem(Ljava/lang/String;)Ljava/security/PrivateKey;
intermediary method_43519
Lnet/minecraft/class_3515;method_43519(Ljava/lang/String;)Ljava/security/PrivateKey;
official a
Laxl;a(Ljava/lang/String;)Ljava/security/PrivateKey;
-
decodeRsaPublicKeyPem
Decodes a PEM-formatted RSA public key.A PEM-formatted RSA public key is "-----BEGIN RSA PUBLIC KEY-----", followed by Base64 encoded X.509 encoded key, followed by "-----END RSA PUBLIC KEY-----". Note that this method also allows Base64 encoded keys that have neither the prefix or the suffix.
- Throws:
NetworkEncryptionException
- when the key is malformed- See Also:
- Mappings:
Namespace Name Mixin selector named decodeRsaPublicKeyPem
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPublicKeyPem(Ljava/lang/String;)Ljava/security/PublicKey;
intermediary method_43524
Lnet/minecraft/class_3515;method_43524(Ljava/lang/String;)Ljava/security/PublicKey;
official b
Laxl;b(Ljava/lang/String;)Ljava/security/PublicKey;
-
encodeRsaPublicKey
Encodes an RSA publickey
to a PEM-formatted key string.A PEM-formatted RSA public key is "-----BEGIN RSA PUBLIC KEY-----", followed by Base64 encoded X.509 encoded key, followed by "-----END RSA PUBLIC KEY-----".
- Throws:
IllegalArgumentException
- when non-RSA key is passed- See Also:
- Mappings:
Namespace Name Mixin selector named encodeRsaPublicKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
intermediary method_43522
Lnet/minecraft/class_3515;method_43522(Ljava/security/PublicKey;)Ljava/lang/String;
official a
Laxl;a(Ljava/security/PublicKey;)Ljava/lang/String;
-
encodeRsaPrivateKey
Encodes an RSA privatekey
to a PEM-formatted key string.A PEM-formatted RSA private key is "-----BEGIN RSA PRIVATE KEY-----", followed by Base64 encoded PCKS #8 encoded key, followed by "-----END RSA PRIVATE KEY-----".
- Throws:
IllegalArgumentException
- when non-RSA key is passed- See Also:
- Mappings:
Namespace Name Mixin selector named encodeRsaPrivateKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPrivateKey(Ljava/security/PrivateKey;)Ljava/lang/String;
intermediary method_43521
Lnet/minecraft/class_3515;method_43521(Ljava/security/PrivateKey;)Ljava/lang/String;
official a
Laxl;a(Ljava/security/PrivateKey;)Ljava/lang/String;
-
decodeEncodedRsaPrivateKey
Decodes a PCKS #8-encoded RSA private key.- Throws:
NetworkEncryptionException
- when the key is malformed- See Also:
- Mappings:
Namespace Name Mixin selector named decodeEncodedRsaPrivateKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPrivateKey([B)Ljava/security/PrivateKey;
intermediary method_43525
Lnet/minecraft/class_3515;method_43525([B)Ljava/security/PrivateKey;
official b
Laxl;b([B)Ljava/security/PrivateKey;
-
decodeEncodedRsaPublicKey
Decodes a X.509-encoded RSA public key.- Throws:
NetworkEncryptionException
- when the key is malformed- See Also:
- Mappings:
Namespace Name Mixin selector named decodeEncodedRsaPublicKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPublicKey([B)Ljava/security/PublicKey;
intermediary method_15242
Lnet/minecraft/class_3515;method_15242([B)Ljava/security/PublicKey;
official a
Laxl;a([B)Ljava/security/PublicKey;
-
decryptSecretKey
public static SecretKey decryptSecretKey(PrivateKey privateKey, byte[] encryptedSecretKey) throws NetworkEncryptionException Decrypts RSA-encrypted AES secret key.- Throws:
NetworkEncryptionException
- when the secret key is malformed- Mappings:
Namespace Name Mixin selector named decryptSecretKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decryptSecretKey(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
intermediary method_15234
Lnet/minecraft/class_3515;method_15234(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
official a
Laxl;a(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
-
encrypt
Encrypts a data. The algorithm is determined from the key used.- Parameters:
key
- encryption key (e.g. AES secret key or RSA public key)- Throws:
NetworkEncryptionException
- when encryption fails, e.g. due to invalid key- See Also:
- Mappings:
Namespace Name Mixin selector named encrypt
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encrypt(Ljava/security/Key;[B)[B
intermediary method_15238
Lnet/minecraft/class_3515;method_15238(Ljava/security/Key;[B)[B
official a
Laxl;a(Ljava/security/Key;[B)[B
-
decrypt
Decrypts an encrypted data. The algorithm is determined from the key used.- Parameters:
key
- decryption key (e.g. AES secret key or RSA private key)- Throws:
NetworkEncryptionException
- when decryption fails, e.g. due to invalid key- See Also:
- Mappings:
Namespace Name Mixin selector named decrypt
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decrypt(Ljava/security/Key;[B)[B
intermediary method_15243
Lnet/minecraft/class_3515;method_15243(Ljava/security/Key;[B)[B
official b
Laxl;b(Ljava/security/Key;[B)[B
-
crypt
Low-level API to perform encryption or decryption operation.- Throws:
NetworkEncryptionException
- when the operation fails- Mappings:
Namespace Name Mixin selector named crypt
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;crypt(ILjava/security/Key;[B)[B
intermediary method_15244
Lnet/minecraft/class_3515;method_15244(ILjava/security/Key;[B)[B
official a
Laxl;a(ILjava/security/Key;[B)[B
-
createCipher
Creates a cipher to perform encryption or decryption operation.- Throws:
Exception
- Mappings:
Namespace Name Mixin selector named createCipher
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;createCipher(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;
intermediary method_15241
Lnet/minecraft/class_3515;method_15241(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;
official a
Laxl;a(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;
-
cipherFromKey
Creates an AES cipher from the key.- Parameters:
key
- the AES secret key- Throws:
NetworkEncryptionException
- when creation fails, e.g. due to invalid key- Mappings:
Namespace Name Mixin selector named cipherFromKey
Lnet/minecraft/network/encryption/NetworkEncryptionUtils;cipherFromKey(ILjava/security/Key;)Ljavax/crypto/Cipher;
intermediary method_15235
Lnet/minecraft/class_3515;method_15235(ILjava/security/Key;)Ljavax/crypto/Cipher;
official a
Laxl;a(ILjava/security/Key;)Ljavax/crypto/Cipher;
-