Class NetworkEncryptionUtils
- API Note:
 - Methods in this class usually throw 
NetworkEncryptionExceptionwhen 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/NetworkEncryptionUtilsintermediary net/minecraft/class_3515official bax
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceNetworkEncryptionUtils.KeyDecoder<T extends Key>A functional interface that decodes an encoded key.static classUtilities for working with a secure random number generator.static final recordA record holding a signature of a data and the salt added while signing. - 
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final intstatic final Base64.Encoderprivate static final Stringstatic final Stringprivate static final Stringprivate static final intstatic final com.mojang.serialization.Codec<PrivateKey> The codec for RSA private keys.private static final Stringprivate static final Stringstatic final com.mojang.serialization.Codec<PublicKey> The codec for RSA public keys.static final Stringprivate static final Stringprivate static final Stringstatic final intstatic final String - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic CiphercipherFromKey(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 CiphercreateCipher(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 PrivateKeydecodeEncodedRsaPrivateKey(byte[] key) Decodes a PCKS #8-encoded RSA private key.static PublicKeydecodeEncodedRsaPublicKey(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 PrivateKeyDecodes a PEM-formatted RSA private key.static PublicKeyDecodes a PEM-formatted RSA public key.static byte[]Decrypts an encrypted data.static SecretKeydecryptSecretKey(PrivateKey privateKey, byte[] encryptedSecretKey) Decrypts RSA-encrypted AES secret key.static StringEncodes an RSA privatekeyto a PEM-formatted key string.static StringEncodes an RSA publickeyto a PEM-formatted key string.static byte[]Encrypts a data.static SecretKeyReturns a new 128 bit AES secret key.static KeyPairReturns 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 AESLnet/minecraft/network/encryption/NetworkEncryptionUtils;AES:Ljava/lang/String;intermediary field_29830Lnet/minecraft/class_3515;field_29830:Ljava/lang/String;official hLbax;h:Ljava/lang/String;
 - 
AES_KEY_LENGTH
private static final int AES_KEY_LENGTH- See Also:
 - Mappings:
 Namespace Name Mixin selector named AES_KEY_LENGTHLnet/minecraft/network/encryption/NetworkEncryptionUtils;AES_KEY_LENGTH:Iintermediary field_29831Lnet/minecraft/class_3515;field_29831:Iofficial iLbax;i:I
 - 
RSA
- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSALnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA:Ljava/lang/String;intermediary field_29832Lnet/minecraft/class_3515;field_29832:Ljava/lang/String;official jLbax;j:Ljava/lang/String;
 - 
RSA_KEY_LENGTH
private static final int RSA_KEY_LENGTH- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSA_KEY_LENGTHLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_KEY_LENGTH:Iintermediary field_29833Lnet/minecraft/class_3515;field_29833:Iofficial kLbax;k:I
 - 
ISO_8859_1
- See Also:
 - Mappings:
 Namespace Name Mixin selector named ISO_8859_1Lnet/minecraft/network/encryption/NetworkEncryptionUtils;ISO_8859_1:Ljava/lang/String;intermediary field_29834Lnet/minecraft/class_3515;field_29834:Ljava/lang/String;official lLbax;l:Ljava/lang/String;
 - 
SHA1
- See Also:
 - Mappings:
 Namespace Name Mixin selector named SHA1Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA1:Ljava/lang/String;intermediary field_29835Lnet/minecraft/class_3515;field_29835:Ljava/lang/String;official mLbax;m:Ljava/lang/String;
 - 
SHA256_WITH_RSA
- See Also:
 - Mappings:
 Namespace Name Mixin selector named SHA256_WITH_RSALnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_WITH_RSA:Ljava/lang/String;intermediary field_39109Lnet/minecraft/class_3515;field_39109:Ljava/lang/String;official aLbax;a:Ljava/lang/String;
 - 
SHA256_BITS
public static final int SHA256_BITS- See Also:
 - Mappings:
 Namespace Name Mixin selector named SHA256_BITSLnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_BITS:Iintermediary field_40111Lnet/minecraft/class_3515;field_40111:Iofficial bLbax;b:I
 - 
RSA_PRIVATE_KEY_PREFIX
- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSA_PRIVATE_KEY_PREFIXLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_PREFIX:Ljava/lang/String;intermediary field_39037Lnet/minecraft/class_3515;field_39037:Ljava/lang/String;official nLbax;n:Ljava/lang/String;
 - 
RSA_PRIVATE_KEY_SUFFIX
- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSA_PRIVATE_KEY_SUFFIXLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_SUFFIX:Ljava/lang/String;intermediary field_39038Lnet/minecraft/class_3515;field_39038:Ljava/lang/String;official oLbax;o:Ljava/lang/String;
 - 
RSA_PUBLIC_KEY_PREFIX
- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSA_PUBLIC_KEY_PREFIXLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_PREFIX:Ljava/lang/String;intermediary field_39033Lnet/minecraft/class_3515;field_39033:Ljava/lang/String;official cLbax;c:Ljava/lang/String;
 - 
RSA_PUBLIC_KEY_SUFFIX
- See Also:
 - Mappings:
 Namespace Name Mixin selector named RSA_PUBLIC_KEY_SUFFIXLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_SUFFIX:Ljava/lang/String;intermediary field_39039Lnet/minecraft/class_3515;field_39039:Ljava/lang/String;official pLbax;p:Ljava/lang/String;
 - 
LINEBREAK
- See Also:
 - Mappings:
 Namespace Name Mixin selector named LINEBREAKLnet/minecraft/network/encryption/NetworkEncryptionUtils;LINEBREAK:Ljava/lang/String;intermediary field_39034Lnet/minecraft/class_3515;field_39034:Ljava/lang/String;official dLbax;d:Ljava/lang/String;
 - 
BASE64_ENCODER
- Mappings:
 Namespace Name Mixin selector named BASE64_ENCODERLnet/minecraft/network/encryption/NetworkEncryptionUtils;BASE64_ENCODER:Ljava/util/Base64$Encoder;intermediary field_39272Lnet/minecraft/class_3515;field_39272:Ljava/util/Base64$Encoder;official eLbax;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_CODECLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_CODEC:Lcom/mojang/serialization/Codec;intermediary field_39035Lnet/minecraft/class_3515;field_39035:Lcom/mojang/serialization/Codec;official fLbax;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_CODECLnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_CODEC:Lcom/mojang/serialization/Codec;intermediary field_39036Lnet/minecraft/class_3515;field_39036:Lcom/mojang/serialization/Codec;official gLbax;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 generateSecretKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;generateSecretKey()Ljavax/crypto/SecretKey;intermediary method_15239Lnet/minecraft/class_3515;method_15239()Ljavax/crypto/SecretKey;official aLbax;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 generateServerKeyPairLnet/minecraft/network/encryption/NetworkEncryptionUtils;generateServerKeyPair()Ljava/security/KeyPair;intermediary method_15237Lnet/minecraft/class_3515;method_15237()Ljava/security/KeyPair;official bLbax;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 computeServerIdLnet/minecraft/network/encryption/NetworkEncryptionUtils;computeServerId(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[Bintermediary method_15240Lnet/minecraft/class_3515;method_15240(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[Bofficial aLbax;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 hashLnet/minecraft/network/encryption/NetworkEncryptionUtils;hash([[B)[Bintermediary method_15236Lnet/minecraft/class_3515;method_15236([[B)[Bofficial aLbax;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 thedecoderthrows, e.g. due to invalid key content- Mappings:
 Namespace Name Mixin selector named decodePemLnet/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_43520Lnet/minecraft/class_3515;method_43520(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lnet/minecraft/class_3515$class_7424;)Ljava/security/Key;official aLbax;a(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lbax$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 decodeRsaPrivateKeyPemLnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPrivateKeyPem(Ljava/lang/String;)Ljava/security/PrivateKey;intermediary method_43519Lnet/minecraft/class_3515;method_43519(Ljava/lang/String;)Ljava/security/PrivateKey;official aLbax;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 decodeRsaPublicKeyPemLnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPublicKeyPem(Ljava/lang/String;)Ljava/security/PublicKey;intermediary method_43524Lnet/minecraft/class_3515;method_43524(Ljava/lang/String;)Ljava/security/PublicKey;official bLbax;b(Ljava/lang/String;)Ljava/security/PublicKey;
 - 
encodeRsaPublicKey
Encodes an RSA publickeyto 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 encodeRsaPublicKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;intermediary method_43522Lnet/minecraft/class_3515;method_43522(Ljava/security/PublicKey;)Ljava/lang/String;official aLbax;a(Ljava/security/PublicKey;)Ljava/lang/String;
 - 
encodeRsaPrivateKey
Encodes an RSA privatekeyto 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 encodeRsaPrivateKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPrivateKey(Ljava/security/PrivateKey;)Ljava/lang/String;intermediary method_43521Lnet/minecraft/class_3515;method_43521(Ljava/security/PrivateKey;)Ljava/lang/String;official aLbax;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 decodeEncodedRsaPrivateKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPrivateKey([B)Ljava/security/PrivateKey;intermediary method_43525Lnet/minecraft/class_3515;method_43525([B)Ljava/security/PrivateKey;official bLbax;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 decodeEncodedRsaPublicKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPublicKey([B)Ljava/security/PublicKey;intermediary method_15242Lnet/minecraft/class_3515;method_15242([B)Ljava/security/PublicKey;official aLbax;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 decryptSecretKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;decryptSecretKey(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;intermediary method_15234Lnet/minecraft/class_3515;method_15234(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;official aLbax;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 encryptLnet/minecraft/network/encryption/NetworkEncryptionUtils;encrypt(Ljava/security/Key;[B)[Bintermediary method_15238Lnet/minecraft/class_3515;method_15238(Ljava/security/Key;[B)[Bofficial aLbax;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 decryptLnet/minecraft/network/encryption/NetworkEncryptionUtils;decrypt(Ljava/security/Key;[B)[Bintermediary method_15243Lnet/minecraft/class_3515;method_15243(Ljava/security/Key;[B)[Bofficial bLbax;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 cryptLnet/minecraft/network/encryption/NetworkEncryptionUtils;crypt(ILjava/security/Key;[B)[Bintermediary method_15244Lnet/minecraft/class_3515;method_15244(ILjava/security/Key;[B)[Bofficial aLbax;a(ILjava/security/Key;[B)[B
 - 
createCipher
Creates a cipher to perform encryption or decryption operation.- Throws:
 Exception- Mappings:
 Namespace Name Mixin selector named createCipherLnet/minecraft/network/encryption/NetworkEncryptionUtils;createCipher(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;intermediary method_15241Lnet/minecraft/class_3515;method_15241(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;official aLbax;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 cipherFromKeyLnet/minecraft/network/encryption/NetworkEncryptionUtils;cipherFromKey(ILjava/security/Key;)Ljavax/crypto/Cipher;intermediary method_15235Lnet/minecraft/class_3515;method_15235(ILjava/security/Key;)Ljavax/crypto/Cipher;official aLbax;a(ILjava/security/Key;)Ljavax/crypto/Cipher;
 
 -