public static SecretKey getSecret(EncryptionResponse resp, EncryptionRequest request) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance( "RSA" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); byte[] decrypted = cipher.doFinal( resp.getVerifyToken() ); if ( !Arrays.equals( request.getVerifyToken(), decrypted ) ) { throw new IllegalStateException( "Key pairs do not match!" ); } cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); return new SecretKeySpec( cipher.doFinal( resp.getSharedSecret() ), "AES" ); }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeArray( sharedSecret, buf ); writeArray( verifyToken, buf ); }
@Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { writeArrayLegacy( sharedSecret, buf, false ); writeArrayLegacy( verifyToken, buf, false ); } else { writeArray( sharedSecret, buf ); writeArray( verifyToken, buf ); } }
@Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 ) { sharedSecret = readArrayLegacy( buf ); verifyToken = readArrayLegacy( buf ); } else { sharedSecret = readArray( buf, 128 ); verifyToken = readArray( buf, 128 ); } }
public static SecretKey getSecret(EncryptionResponse resp, EncryptionRequest request) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance( "RSA" ); cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); byte[] decrypted = cipher.doFinal( resp.getVerifyToken() ); if ( !Arrays.equals( request.getVerifyToken(), decrypted ) ) { throw new IllegalStateException( "Key pairs do not match!" ); } cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() ); return new SecretKeySpec( cipher.doFinal( resp.getSharedSecret() ), "AES" ); }