Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.89 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Date;
  3. import java.security.*;
  4. import java.math.BigInteger;
  5.  
  6. class LastFM {
  7.     String sessionkey = "";
  8.     String username = "";
  9.     String password = "";
  10.  
  11.     public LastFM() {
  12.         readConfig("lastfm_config.txt");
  13.         System.out.println("lastfm username: " + username + ", password: " + doAskterisks(password));
  14.         System.out.println(authKey(password));     
  15.     }
  16.    
  17.     public static void main(String[] args) {
  18.         if(args.length < 3) {
  19.             System.out.println("Error: not enough args!");
  20.             return;
  21.         }
  22.         LastFM scrobbler = new LastFM();
  23.     }
  24.  
  25.     private String authKey(String pass) {
  26.         long sec;
  27.         Date date;
  28.         MessageDigest md;
  29.         BigInteger i;      
  30.         String passhash;       
  31.         try {
  32.             date = new Date();
  33.             sec = date.getTime() / 1000;
  34.             md = MessageDigest.getInstance("MD5");
  35.             md.update(pass.getBytes("iso-8859-1"), 0, pass.length());
  36.             i = new BigInteger(1,md.digest());
  37.             passhash = String.format("%1$032X", i) + String.valueOf(sec);
  38.             md = MessageDigest.getInstance("MD5");
  39.             md.update(passhash.getBytes("iso-8859-1"), 0, passhash.length());
  40.             i = new BigInteger(1,md.digest());
  41.             return String.format("%1$032X", i);
  42.         } catch (Exception e) {
  43.             return "";
  44.         }
  45.     }
  46.  
  47.     private String getSessionKey(String authKey) {
  48.         authKey = authKey(password);
  49.         /* XXX: Code goes here */
  50.         return "";
  51.     }
  52.  
  53.     private String doAskterisks(String pass) {
  54.         String ob = "";
  55.         for(int i = 0; i < pass.length(); i++) {
  56.             ob += "*";
  57.         }
  58.         return ob;
  59.     }
  60.  
  61.     private void readConfig(String file) {
  62.         BufferedReader in = null;
  63.         try {
  64.             in = new BufferedReader(new FileReader(file));
  65.             username = in.readLine();
  66.             password = in.readLine();
  67.         } catch(java.io.IOException e) {
  68.             System.err.println("Caught java.io.IOException: " + e.getMessage());
  69.         } finally {
  70.             if(in != null) {
  71.                 try {
  72.                     in.close();
  73.                 } catch(java.io.IOException e) {
  74.                     System.err.println("Caught java.io.IOException: " + e.getMessage());
  75.                 }  
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement