Hi, i recently begun learning java and encryption.
I found some code from a website that is supposed to decrypt lastlogin files found in minecraft.
When i try to compile it gives me these errors:

C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:54: error: invalid method declaration; return type required
    public MineCraftLoginReader() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: illegal start of type
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: ';' expected
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: illegal start of type
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: ';' expected
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: invalid method declaration; return type required
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:87: error: ';' expected
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:88: error: ')' expected
        }
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:91: error: illegal start of expression
    private static Path getDefaultLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:91: error: ';' expected
    private static Path getDefaultLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:91: error: ';' expected
    private static Path getDefaultLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:103: error: illegal start of expression
    private static Path getNixLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:103: error: illegal start of expression
    private static Path getNixLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:103: error: ';' expected
    private static Path getNixLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:103: error: ';' expected
    private static Path getNixLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:107: error: illegal start of expression
    private static Path getMacLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:107: error: illegal start of expression
    private static Path getMacLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:107: error: ';' expected
    private static Path getMacLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:107: error: ';' expected
    private static Path getMacLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:112: error: illegal start of expression
    private static Path getWindowsLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:112: error: illegal start of expression
    private static Path getWindowsLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:112: error: ';' expected
    private static Path getWindowsLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:112: error: ';' expected
    private static Path getWindowsLoginFile() {
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\src\lastlogin\decryptor\LastloginDecryptor.java:119: error: reached end of file while parsing
}
24 errors
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\nbproject\build-impl.xml:920: The following error occurred while executing this line:
C:\Users\CROCCY\Documents\NetBeansProjects\Lastlogin decryptor\nbproject\build-impl.xml:260: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

This is the entire program:

package lastlogin.decryptor;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Random;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

public class LastLoginDecryptor {

    private static final long MAGIC_SEED = 43287234L;
    private static final int SALT_LENGTH = 8;
    private static final String LOGIN_FILE_NAME = "lastlogin";
    private static final String USER_HOME = System
            .getProperty("user.home", ".");
    private static final String NEWLINE = System.getProperty("line.separator");
    private static final char[] PASSWORD = "passwordfile".toCharArray();

    private Cipher cipher;

    public static void main(String[] args) {
        Path login = null;
        if (args.length == 1) {
            login = Paths.get(args[0]);
        } else {
            login = getDefaultLoginFile();
        }
        System.out.println("reading file: " + login);
        if (login != null && Files.exists(login)) {
            try {
                System.out.println(new MineCraftLoginReader().decrypt(login));
            } catch (IOException e) {
                System.err.println(e.getMessage());
            }
        } else {
            System.err.println("login not found");
        }
    }

    public MineCraftLoginReader() {
        initCipher();
    }

    private void initCipher() {
        final int iterationCount = 5;
        PBEParameterSpec paramSpec = new PBEParameterSpec(initSalt(),
                iterationCount);
        PBEKeySpec keySpec = new PBEKeySpec(PASSWORD);
        try {
            SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES")
                    .generateSecret(keySpec);
            cipher = Cipher.getInstance("PBEWithMD5AndDES");
            cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
        } catch (InvalidKeySpecException | NoSuchAlgorithmException
                | NoSuchPaddingException | InvalidKeyException
                | InvalidAlgorithmParameterException e) {
            e.printStackTrace();
        }
    }

    private byte[] initSalt() {
        byte[] salt = new byte[SALT_LENGTH];
        Random rand = new Random(MAGIC_SEED);
        rand.nextBytes(salt);
        return salt;
    }

    public String decrypt(Path loginFile) throws FileNotFoundException,
            IOException {
        try (FileInputStream fis = new FileInputStream(loginFile.toFile());
                CipherInputStream cis = new CipherInputStream(fis, cipher);
                DataInputStream dis = new DataInputStream(cis) {
                return "name: "+dis.readUTF()+NEWLINE+"password: "+dis.readUTF();
        }
    }

    private static Path getDefaultLoginFile() {
        String os = System.getProperty("os.name").toLowerCase();

        if (os.contains("windows")) {
            return getWindowsLoginFile();
        }
        if (os.contains("mac")) {
            return getMacLoginFile();
        }
        return getNixLoginFile();
    }

    private static Path getNixLoginFile() {
        return Paths.get(USER_HOME, ".minecraft", LOGIN_FILE_NAME);
    }

    private static Path getMacLoginFile() {
        return Paths.get(USER_HOME, "Library", "Application Support",
                "minecraft", LOGIN_FILE_NAME);
    }

    private static Path getWindowsLoginFile() {
        String appData = System.getenv("APPDATA");
        if (appData != null) {
            return Paths.get(appData, ".minecraft", LOGIN_FILE_NAME);
        }
        return Paths.get(USER_HOME, ".minecraft", LOGIN_FILE_NAME);
    }
}

Could anyone please tell me what these errors mean?

The first error is easy - you are not specifying a return type. In Java, only constructors do not specify return types. Did you copy and paste this code into a new .java file? It looks like the original file was called MineCraftLoginReader.java - but you've changed that. Java requires that public classes and filenames match.

The second error, pretty much everything after that, are syntax errors. That is not proper Java code, and would never compile. Perhaps you made some mistakes when you copied the code? That might explain it as I see missing { brackets, ;'s in the wrong place etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.