2016-12-29 5 views
0

文字列をNTLMハッシュに変換できますか? Javaにインポートできるライブラリがありますか、それを取得するためのメソッドがありますか?文字列をJavaでNTLMハッシュに変換できますか?

+0

私は、全体の事はあると思います。私が言っていることは、あなたはたぶんそのことの具体的な実装について話しています。いくつかの特定のライブラリから来ています。そのライブラリに "NTMLハッシュ"オブジェクトを作成する方法を理解するために、その非常にライブラリを調べるべきではありませんか? – GhostCat

+2

私はウェブを高値と低値で検索しましたが、NTMLが何であるかはまだ分かりません。私が見つけたすべての検索結果は、NTLMのスペルミスです。 NTLMを意味しましたか? – VGR

+0

@VGRはいNTLM申し訳ありません – RACING121

答えて

0

私は、このユーティリティクラスを書いた:

import jcifs.smb.NtlmPasswordAuthentication; 

/** 
* NTLM passwords encoding. 
* 
* This implementation depends on the JCIFS library. 
*/ 
public class NTLMPassword { 

    private final static char[] HEX_ARRAY = "ABCDEF".toCharArray(); 

    private NTLMPassword() { 
     throw new UnsupportedOperationException("Can not instantiate this class."); 
    } 

    /** 
    * Return NTLM hash for a given string. 
    * 
    * See https://lists.samba.org/archive/jcifs/2015-February/010258.html 
    * 
    * @param value 
    *   the string to hash. 
    * @return the NTLM hash for the given string. 
    */ 
    public static String encode(String value) { 
     String s = (value != null) ? value : ""; 
     byte[] hash = NtlmPasswordAuthentication.nTOWFv1(s); 
     return bytesToHex(hash).toUpperCase(); 
    } 

    /** 
    * See https://stackoverflow.com/a/9855338/1314986 
    */ 
    private static String bytesToHex(byte[] bytes) { 
     char[] hexChars = new char[bytes.length * 2]; 
     for (int j = 0; j < bytes.length; j++) { 
      int v = bytes[j] & 0xFF; 
      hexChars[j * 2] = HEX_ARRAY[v >>> 4]; 
      hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; 
     } 
     return new String(hexChars); 
    } 
} 

このコードは、JCIFSライブラリを使用しています。あなたは、Mavenを使用する場合は、次の依存関係を含める:あなたは、次のテストでこのコードを検証することができ

<dependency> 
    <groupId>org.codelibs</groupId> 
    <artifactId>jcifs</artifactId> 
    <version>1.3.18.2</version> 
</dependency> 

:NTMLハッシュを表す何クラス:

@Test 
public void testEncode() throws Exception { 
    assertEquals("D36D0FC68CEDDAF7E180A6AE71096B35", NTLMPassword.encode("DummyPassword")); 
} 
+0

これははるかに簡単です – RACING121

関連する問題