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 - official - anz- intermediary - net/minecraft/class_3515- named - net/minecraft/network/encryption/NetworkEncryptionUtils
- 
Nested Class SummaryNested 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 SummaryFieldsModifier 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 SummaryConstructors
- 
Method SummaryModifier 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 - official - h- Lanz;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_LENGTHprivate static final int AES_KEY_LENGTH- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - i- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - j- Lanz;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_LENGTHprivate static final int RSA_KEY_LENGTH- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - k- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - l- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - m- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;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_BITSpublic static final int SHA256_BITS- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - b- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - n- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - o- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - c- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - p- Lanz;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- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - d- Lanz;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- Mappings:
- Namespace - Name - Mixin selector - official - e- Lanz;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_CODECThe codec for RSA public keys.- See Also:
- Implementation Note:
- The key is encoded using the PEM format.
- Mappings:
- Namespace - Name - Mixin selector - official - f- Lanz;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_CODECThe codec for RSA private keys.- See Also:
- Implementation Note:
- The key is encoded using the PEM format.
- Mappings:
- Namespace - Name - Mixin selector - official - g- Lanz;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- 
NetworkEncryptionUtilspublic NetworkEncryptionUtils()
 
- 
- 
Method Details- 
generateSecretKeyReturns 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- Lanz;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;
 
- 
generateServerKeyPairReturns 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- Lanz;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;
 
- 
computeServerIdpublic 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 - official - a- Lanz;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
 
- 
hashReturns the SHA-1 hash ofbytes.- Returns:
- the SHA-1 hash of bytes
- Throws:
- Exception
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;a([[B)[B- intermediary - method_15236- Lnet/minecraft/class_3515;method_15236([[B)[B- named - hash- Lnet/minecraft/network/encryption/NetworkEncryptionUtils;hash([[B)[B
 
- 
decodePemprivate 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 the- decoderthrows, e.g. due to invalid key content
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;a(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lanz$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;
 
- 
decodeRsaPrivateKeyPemDecodes 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- Lanz;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;
 
- 
decodeRsaPublicKeyPemDecodes 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- Lanz;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;
 
- 
encodeRsaPublicKeyEncodes 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 - official - a- Lanz;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;
 
- 
encodeRsaPrivateKeyEncodes 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 - official - a- Lanz;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;
 
- 
decodeEncodedRsaPrivateKeyDecodes a PCKS #8-encoded RSA private key.- Throws:
- NetworkEncryptionException- when the key is malformed
- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - b- Lanz;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;
 
- 
decodeEncodedRsaPublicKeyDecodes a X.509-encoded RSA public key.- Throws:
- NetworkEncryptionException- when the key is malformed
- See Also:
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;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;
 
- 
decryptSecretKeypublic 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- Lanz;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;
 
- 
encryptEncrypts 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- Lanz;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
 
- 
decryptDecrypts 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- Lanz;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
 
- 
cryptLow-level API to perform encryption or decryption operation.- Throws:
- NetworkEncryptionException- when the operation fails
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;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
 
- 
createCipherCreates a cipher to perform encryption or decryption operation.- Throws:
- Exception
- Mappings:
- Namespace - Name - Mixin selector - official - a- Lanz;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;
 
- 
cipherFromKeyCreates 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- Lanz;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;
 
 
-