Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Date;
- import java.security.*;
- import java.math.BigInteger;
- class LastFM {
- String sessionkey = "";
- String username = "";
- String password = "";
- public LastFM() {
- readConfig("lastfm_config.txt");
- System.out.println("lastfm username: " + username + ", password: " + doAskterisks(password));
- System.out.println(authKey(password));
- }
- public static void main(String[] args) {
- if(args.length < 3) {
- System.out.println("Error: not enough args!");
- return;
- }
- LastFM scrobbler = new LastFM();
- }
- private String authKey(String pass) {
- long sec;
- Date date;
- MessageDigest md;
- BigInteger i;
- String passhash;
- try {
- date = new Date();
- sec = date.getTime() / 1000;
- md = MessageDigest.getInstance("MD5");
- md.update(pass.getBytes("iso-8859-1"), 0, pass.length());
- i = new BigInteger(1,md.digest());
- passhash = String.format("%1$032X", i) + String.valueOf(sec);
- md = MessageDigest.getInstance("MD5");
- md.update(passhash.getBytes("iso-8859-1"), 0, passhash.length());
- i = new BigInteger(1,md.digest());
- return String.format("%1$032X", i);
- } catch (Exception e) {
- return "";
- }
- }
- private String getSessionKey(String authKey) {
- authKey = authKey(password);
- /* XXX: Code goes here */
- return "";
- }
- private String doAskterisks(String pass) {
- String ob = "";
- for(int i = 0; i < pass.length(); i++) {
- ob += "*";
- }
- return ob;
- }
- private void readConfig(String file) {
- BufferedReader in = null;
- try {
- in = new BufferedReader(new FileReader(file));
- username = in.readLine();
- password = in.readLine();
- } catch(java.io.IOException e) {
- System.err.println("Caught java.io.IOException: " + e.getMessage());
- } finally {
- if(in != null) {
- try {
- in.close();
- } catch(java.io.IOException e) {
- System.err.println("Caught java.io.IOException: " + e.getMessage());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement