skip to Main Content

Working on building a Java version of a Putty .ppk reader.

I found a PHP version, but I’m stuck on converting some functionality into Java:

    $password = 'blah';
    $symkey = '';
    $sequence = 0;
    while (strlen($symkey) < 32) {
      $temp = pack('Na*', $sequence++, $password);
      $symkey.= pack('H*', sha1($temp));
    }
    $symkey = substr($symkey, 0, 32);

I understand that $symkey.= pack('H*', sha1($temp)); is calling a sha1 hashing function, and I can do that in java, so that can remain a black-box for this. I’m assuming the pack('H*') is just converting the results of the sha1 hash to hex? It’s the pack('Na*' that I can’t grock (or find help with on Google)

Can someone help me, or point me in the right direction?

Thanks so much!

2

Answers


  1. Chosen as BEST ANSWER

    Will this do what I think it will?

    final   int             len         =   32;
    final   String          pass        =   args[0];
    final   StringBuilder   sb          =   new StringBuilder(pass);
                            sb.reverse();
                            sb.setLength(len);
                            sb.reverse();
                System.out.println("len:"+sb.length()+" sb:"+sb);
    final   MessageDigest   crypt       =   MessageDigest.getInstance("SHA-1");
                            crypt.reset();
    final   StringBuilder   sb2         =   new StringBuilder();
                while(sb2.length()<len) {
                            sb2.append(Base64.encodeBase64String(crypt.digest(String.valueOf(sb2).getBytes())));
                }           sb2.setLength(len);
    final   String          base64pass  =   String.valueOf(sb2);
                System.out.println(base64pass);
    

  2. Assumin that pack is hashing function :

    String password = 'blah';
    String  symkey  = '';
        int sequence = 0;
        while (symkey.length < 32) {
          String temp = pack("Na*", sequence++, password);
          symkey = pack("H*", sha1(temp));
        }
        symkey = symkey.substring(0, 32);
    

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search