Class NetworkEncryptionUtils

java.lang.Object
net.minecraft.network.encryption.NetworkEncryptionUtils

public class NetworkEncryptionUtils extends Object
Utilities for encryption, decryption, signing, and hashing of data.
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
official aoj
intermediary net/minecraft/class_3515
named net/minecraft/network/encryption/NetworkEncryptionUtils
  • Field Details

    • AES

      private static final String AES
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official h Laoj;h:Ljava/lang/String;
      intermediary field_29830 Lnet/minecraft/class_3515;field_29830:Ljava/lang/String;
      named AES Lnet/minecraft/network/encryption/NetworkEncryptionUtils;AES:Ljava/lang/String;
    • AES_KEY_LENGTH

      private static final int AES_KEY_LENGTH
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official i Laoj;i:I
      intermediary field_29831 Lnet/minecraft/class_3515;field_29831:I
      named AES_KEY_LENGTH Lnet/minecraft/network/encryption/NetworkEncryptionUtils;AES_KEY_LENGTH:I
    • RSA

      private static final String RSA
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official j Laoj;j:Ljava/lang/String;
      intermediary field_29832 Lnet/minecraft/class_3515;field_29832:Ljava/lang/String;
      named RSA Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA:Ljava/lang/String;
    • RSA_KEY_LENGTH

      private static final int RSA_KEY_LENGTH
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official k Laoj;k:I
      intermediary field_29833 Lnet/minecraft/class_3515;field_29833:I
      named RSA_KEY_LENGTH Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_KEY_LENGTH:I
    • ISO_8859_1

      private static final String ISO_8859_1
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official l Laoj;l:Ljava/lang/String;
      intermediary field_29834 Lnet/minecraft/class_3515;field_29834:Ljava/lang/String;
      named ISO_8859_1 Lnet/minecraft/network/encryption/NetworkEncryptionUtils;ISO_8859_1:Ljava/lang/String;
    • SHA1

      private static final String SHA1
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official m Laoj;m:Ljava/lang/String;
      intermediary field_29835 Lnet/minecraft/class_3515;field_29835:Ljava/lang/String;
      named SHA1 Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA1:Ljava/lang/String;
    • SHA256_WITH_RSA

      public static final String SHA256_WITH_RSA
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a:Ljava/lang/String;
      intermediary field_39109 Lnet/minecraft/class_3515;field_39109:Ljava/lang/String;
      named SHA256_WITH_RSA Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_WITH_RSA:Ljava/lang/String;
    • SHA256_BITS

      public static final int SHA256_BITS
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official b Laoj;b:I
      intermediary field_40111 Lnet/minecraft/class_3515;field_40111:I
      named SHA256_BITS Lnet/minecraft/network/encryption/NetworkEncryptionUtils;SHA256_BITS:I
    • RSA_PRIVATE_KEY_PREFIX

      private static final String RSA_PRIVATE_KEY_PREFIX
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official n Laoj;n:Ljava/lang/String;
      intermediary field_39037 Lnet/minecraft/class_3515;field_39037:Ljava/lang/String;
      named RSA_PRIVATE_KEY_PREFIX Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_PREFIX:Ljava/lang/String;
    • RSA_PRIVATE_KEY_SUFFIX

      private static final String RSA_PRIVATE_KEY_SUFFIX
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official o Laoj;o:Ljava/lang/String;
      intermediary field_39038 Lnet/minecraft/class_3515;field_39038:Ljava/lang/String;
      named RSA_PRIVATE_KEY_SUFFIX Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_SUFFIX:Ljava/lang/String;
    • RSA_PUBLIC_KEY_PREFIX

      public static final String RSA_PUBLIC_KEY_PREFIX
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official c Laoj;c:Ljava/lang/String;
      intermediary field_39033 Lnet/minecraft/class_3515;field_39033:Ljava/lang/String;
      named RSA_PUBLIC_KEY_PREFIX Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_PREFIX:Ljava/lang/String;
    • RSA_PUBLIC_KEY_SUFFIX

      private static final String RSA_PUBLIC_KEY_SUFFIX
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official p Laoj;p:Ljava/lang/String;
      intermediary field_39039 Lnet/minecraft/class_3515;field_39039:Ljava/lang/String;
      named RSA_PUBLIC_KEY_SUFFIX Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_SUFFIX:Ljava/lang/String;
    • LINEBREAK

      public static final String LINEBREAK
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official d Laoj;d:Ljava/lang/String;
      intermediary field_39034 Lnet/minecraft/class_3515;field_39034:Ljava/lang/String;
      named LINEBREAK Lnet/minecraft/network/encryption/NetworkEncryptionUtils;LINEBREAK:Ljava/lang/String;
    • BASE64_ENCODER

      public static final Base64.Encoder BASE64_ENCODER
      Mappings:
      Namespace Name Mixin selector
      official e Laoj;e:Ljava/util/Base64$Encoder;
      intermediary field_39272 Lnet/minecraft/class_3515;field_39272:Ljava/util/Base64$Encoder;
      named BASE64_ENCODER Lnet/minecraft/network/encryption/NetworkEncryptionUtils;BASE64_ENCODER:Ljava/util/Base64$Encoder;
    • RSA_PUBLIC_KEY_CODEC

      public static final com.mojang.serialization.Codec<PublicKey> 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
      official f Laoj;f:Lcom/mojang/serialization/Codec;
      intermediary field_39035 Lnet/minecraft/class_3515;field_39035:Lcom/mojang/serialization/Codec;
      named RSA_PUBLIC_KEY_CODEC Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PUBLIC_KEY_CODEC:Lcom/mojang/serialization/Codec;
    • RSA_PRIVATE_KEY_CODEC

      public static final com.mojang.serialization.Codec<PrivateKey> 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
      official g Laoj;g:Lcom/mojang/serialization/Codec;
      intermediary field_39036 Lnet/minecraft/class_3515;field_39036:Lcom/mojang/serialization/Codec;
      named RSA_PRIVATE_KEY_CODEC Lnet/minecraft/network/encryption/NetworkEncryptionUtils;RSA_PRIVATE_KEY_CODEC:Lcom/mojang/serialization/Codec;
  • Constructor Details

    • NetworkEncryptionUtils

      public NetworkEncryptionUtils()
  • Method Details

    • generateSecretKey

      public static SecretKey generateSecretKey() throws NetworkEncryptionException
      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
      official a Laoj;a()Ljavax/crypto/SecretKey;
      intermediary method_15239 Lnet/minecraft/class_3515;method_15239()Ljavax/crypto/SecretKey;
      named generateSecretKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;generateSecretKey()Ljavax/crypto/SecretKey;
    • generateServerKeyPair

      public static KeyPair generateServerKeyPair() throws NetworkEncryptionException
      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
      official b Laoj;b()Ljava/security/KeyPair;
      intermediary method_15237 Lnet/minecraft/class_3515;method_15237()Ljava/security/KeyPair;
      named generateServerKeyPair Lnet/minecraft/network/encryption/NetworkEncryptionUtils;generateServerKeyPair()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, and secretKey.
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a(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
      named computeServerId Lnet/minecraft/network/encryption/NetworkEncryptionUtils;computeServerId(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[B
    • hash

      private static byte[] hash(byte[][] bytes) throws Exception
      Returns the SHA-1 hash of bytes.
      Returns:
      the SHA-1 hash of bytes
      Throws:
      Exception
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a([[B)[B
      intermediary method_15236 Lnet/minecraft/class_3515;method_15236([[B)[B
      named hash Lnet/minecraft/network/encryption/NetworkEncryptionUtils;hash([[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 by suffix. Note that this method also allows Base64 encoded keys that have neither the prefix or the suffix.

      Throws:
      NetworkEncryptionException - when the decoder throws, e.g. due to invalid key content
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Laoj$a;)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;
      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;
    • decodeRsaPrivateKeyPem

      public static PrivateKey decodeRsaPrivateKeyPem(String key) throws NetworkEncryptionException
      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
      official a Laoj;a(Ljava/lang/String;)Ljava/security/PrivateKey;
      intermediary method_43519 Lnet/minecraft/class_3515;method_43519(Ljava/lang/String;)Ljava/security/PrivateKey;
      named decodeRsaPrivateKeyPem Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPrivateKeyPem(Ljava/lang/String;)Ljava/security/PrivateKey;
    • decodeRsaPublicKeyPem

      public static PublicKey decodeRsaPublicKeyPem(String key) throws NetworkEncryptionException
      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
      official b Laoj;b(Ljava/lang/String;)Ljava/security/PublicKey;
      intermediary method_43524 Lnet/minecraft/class_3515;method_43524(Ljava/lang/String;)Ljava/security/PublicKey;
      named decodeRsaPublicKeyPem Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeRsaPublicKeyPem(Ljava/lang/String;)Ljava/security/PublicKey;
    • encodeRsaPublicKey

      public static String encodeRsaPublicKey(PublicKey key)
      Encodes an RSA public key 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
      official a Laoj;a(Ljava/security/PublicKey;)Ljava/lang/String;
      intermediary method_43522 Lnet/minecraft/class_3515;method_43522(Ljava/security/PublicKey;)Ljava/lang/String;
      named encodeRsaPublicKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPublicKey(Ljava/security/PublicKey;)Ljava/lang/String;
    • encodeRsaPrivateKey

      public static String encodeRsaPrivateKey(PrivateKey key)
      Encodes an RSA private key 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
      official a Laoj;a(Ljava/security/PrivateKey;)Ljava/lang/String;
      intermediary method_43521 Lnet/minecraft/class_3515;method_43521(Ljava/security/PrivateKey;)Ljava/lang/String;
      named encodeRsaPrivateKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encodeRsaPrivateKey(Ljava/security/PrivateKey;)Ljava/lang/String;
    • decodeEncodedRsaPrivateKey

      private static PrivateKey decodeEncodedRsaPrivateKey(byte[] key) throws NetworkEncryptionException
      Decodes a PCKS #8-encoded RSA private key.
      Throws:
      NetworkEncryptionException - when the key is malformed
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official b Laoj;b([B)Ljava/security/PrivateKey;
      intermediary method_43525 Lnet/minecraft/class_3515;method_43525([B)Ljava/security/PrivateKey;
      named decodeEncodedRsaPrivateKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPrivateKey([B)Ljava/security/PrivateKey;
    • decodeEncodedRsaPublicKey

      public static PublicKey decodeEncodedRsaPublicKey(byte[] key) throws NetworkEncryptionException
      Decodes a X.509-encoded RSA public key.
      Throws:
      NetworkEncryptionException - when the key is malformed
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a([B)Ljava/security/PublicKey;
      intermediary method_15242 Lnet/minecraft/class_3515;method_15242([B)Ljava/security/PublicKey;
      named decodeEncodedRsaPublicKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decodeEncodedRsaPublicKey([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
      official a Laoj;a(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
      intermediary method_15234 Lnet/minecraft/class_3515;method_15234(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
      named decryptSecretKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decryptSecretKey(Ljava/security/PrivateKey;[B)Ljavax/crypto/SecretKey;
    • encrypt

      public static byte[] encrypt(Key key, byte[] data) throws NetworkEncryptionException
      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
      official a Laoj;a(Ljava/security/Key;[B)[B
      intermediary method_15238 Lnet/minecraft/class_3515;method_15238(Ljava/security/Key;[B)[B
      named encrypt Lnet/minecraft/network/encryption/NetworkEncryptionUtils;encrypt(Ljava/security/Key;[B)[B
    • decrypt

      public static byte[] decrypt(Key key, byte[] data) throws NetworkEncryptionException
      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
      official b Laoj;b(Ljava/security/Key;[B)[B
      intermediary method_15243 Lnet/minecraft/class_3515;method_15243(Ljava/security/Key;[B)[B
      named decrypt Lnet/minecraft/network/encryption/NetworkEncryptionUtils;decrypt(Ljava/security/Key;[B)[B
    • crypt

      private static byte[] crypt(int opMode, Key key, byte[] data) throws NetworkEncryptionException
      Low-level API to perform encryption or decryption operation.
      Throws:
      NetworkEncryptionException - when the operation fails
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a(ILjava/security/Key;[B)[B
      intermediary method_15244 Lnet/minecraft/class_3515;method_15244(ILjava/security/Key;[B)[B
      named crypt Lnet/minecraft/network/encryption/NetworkEncryptionUtils;crypt(ILjava/security/Key;[B)[B
    • createCipher

      private static Cipher createCipher(int opMode, String algorithm, Key key) throws Exception
      Creates a cipher to perform encryption or decryption operation.
      Throws:
      Exception
      Mappings:
      Namespace Name Mixin selector
      official a Laoj;a(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;
      named createCipher Lnet/minecraft/network/encryption/NetworkEncryptionUtils;createCipher(ILjava/lang/String;Ljava/security/Key;)Ljavax/crypto/Cipher;
    • cipherFromKey

      public static Cipher cipherFromKey(int opMode, Key key) throws NetworkEncryptionException
      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
      official a Laoj;a(ILjava/security/Key;)Ljavax/crypto/Cipher;
      intermediary method_15235 Lnet/minecraft/class_3515;method_15235(ILjava/security/Key;)Ljavax/crypto/Cipher;
      named cipherFromKey Lnet/minecraft/network/encryption/NetworkEncryptionUtils;cipherFromKey(ILjava/security/Key;)Ljavax/crypto/Cipher;