2013-03-26 116 views
2

我公司目前創建和銷售的商業軟件使用Base-64編碼的RSA加密許可證密鑰。結果大概有90個字符。使用起來笨重且笨拙,容易出現用戶錯誤。有些用戶不明白複製和粘貼的情況,並嘗試手動輸入密鑰。如何創建30個字符的許可證密鑰?

我想與如30字符的按鍵我看到一些其他程序使用創建一個較小的鍵,一種方法來取代目前的算法。此外,我注意到許多軟件供應商使用僅使用數字和大寫字符的密鑰,使得它們使用起來更加麻煩。

我可以使用哪些算法來生成嵌入用戶名,產品ID和版本號合理的安全密鑰,其中得到的許可證密鑰是超過30個字符不再,只使用數字和大寫字符?

(如果重要的是,我們的編碼在Java中)。

所以......這裏是一個開始:

public String createLicenseKey(String customerName, String productId, String versionNumber) { 
    // what goes here? 
    return licenseKey; 
} 

String key = createLicenseKey("Max Headroom", "ABCD", "4"); 
// key should now be in format AAAAAA-AAAAAA-AAAAAA-AAAAAA-AAAAAA 
+0

+1,即使我對我們的產品之一看起來一樣。 – 2013-03-26 12:57:37

+0

我不知道人們是如何破解更強大的產品密鑰! – SparKot 2013-03-26 14:12:58

回答

1

對於一些過於具體,你可能要產生自己的算法,將所需的信息包含在散列中,只有您的軟件纔會「理解」。

取信息(用戶名,ID,版本),加一個祕密鹽吧,添加額外的安全層。

你有正確的想法與您的代碼,到目前爲止,只是這裏沒有石頭多設置在特定按鍵的問候。

查看類似的問題,如thisthis以獲取有關該主題的更多信息。

3

我跟着fcm的答案中提到的鏈接,這使我有可能。您需要在Java類路徑中使用Google的Guava庫:

import com.google.common.hash.HashCode; 
import com.google.common.hash.HashFunction; 
import com.google.common.hash.Hashing; 

public class ScratchSpace { 

    public static void main(String[] args) { 
     String userName = "Max Headroom"; 
     String productKey = "ABCD"; 
     String versionNumber = "4"; 

     final String licenseKey = createLicenseKey(userName, productKey, versionNumber); 
     System.out.println("licenseKey = " + licenseKey); 

    } 

    public static String createLicenseKey(String userName, String productKey, String versionNumber) { 
     final String s = userName + "|" + productKey + "|" + versionNumber; 
     final HashFunction hashFunction = Hashing.sha1(); 
     final HashCode hashCode = hashFunction.hashString(s); 
     final String upper = hashCode.toString().toUpperCase(); 
     return group(upper); 
    } 

    private static String group(String s) { 
     String result = ""; 
     for (int i=0; i < s.length(); i++) { 
      if (i%6==0 && i > 0) { 
       result += '-'; 
      } 
      result += s.charAt(i); 
     } 
     return result; 
    } 

} 
相關問題