不建議你們使用此方法激活,若資金容許,請點擊https://www.jetbrains.com/idea/buy/購買正版,謝謝合做!git
用過 IDEA 的同窗應該都知道,這個軟件是收費的,對於筆者來講是很貴了,所以只能另尋他法。 咱們能夠很輕鬆的從網上找到搭建本地激活服務器的教程,可是每次打開 IDEA 都要先打開激活服務器,太麻煩。 或者從網上找別人搭建好的激活服務器,可是可能某一天忽然就用不了了,因此若是有條件仍是本身搭建一個激活服務器比較靠譜。web
一臺能夠遠程訪問的主機 一個 Spring web 項目bash
打開咱們的 Spring 項目,若是沒有的話請自行百度教程,添加一個 Controller服務器
@RestController
@RequestMapping("/rpc")
public class LicenseController {
@RequestMapping("/obtainTicket.action")
public String obtainTicket(String salt, String userName) throws Exception {
String content = "<ObtainTicketResponse>" +
"<message></message>" +
"<prolongationPeriod>607875500</prolongationPeriod>" +
"<responseCode>OK</responseCode>" +
"<salt>" + salt + "</salt>" +
"<ticketId>1</ticketId>" +
"<ticketProperties>licensee=" + userName + " licenseType=0 </ticketProperties>" +
"</ObtainTicketResponse>";
return LicenseUtils.rsaSign(content);
}
@RequestMapping("/releaseTicket.action")
public void releaseTicket(HttpServletResponse httpServletResponse) {
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
@RequestMapping("ping.action")
public String ping(String salt) throws Exception {
String content = "<PingResponse>" +
"<message></message>" +
"<responseCode>OK</responseCode>" +
"<salt>" + salt + "</salt>" +
"</PingResponse>";
return LicenseUtils.rsaSign(content);
}
}
複製代碼
添加工具類app
public class LicenseUtils {
public static String rsaSign(String content) throws Exception {
PrivateKey pk = getPrivateKey();
RSAPrivateKey rpk = (RSAPrivateKey) pk;
byte[] a = hashed(content);
byte[] result = sign(rpk, a);
String mm = byte2HexStr(result).toLowerCase();
return "<!-- " + mm + " -->\n" + content;
}
private static PrivateKey getPrivateKey() throws Exception {
String priKeyData = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAt5yrcHAAjhglnCEn" +
"6yecMWPeUXcMyo0+itXrLlkpcKIIyqPw546bGThhlb1ppX1ySX/OUA4jSakHekNP" +
"5eWPawIDAQABAkBbr9pUPTmpuxkcy9m5LYBrkWk02PQEOV/fyE62SEPPP+GRhv4Q" +
"Fgsu+V2GCwPQ69E3LzKHPsSNpSosIHSO4g3hAiEAywlDfGIl6acnakPrmJE0IL8q" +
"vuO3FtsHBrpkUuOnXakCIQDngkKfjV8XwZn3Rv0vl20VAHb/IhwZfhejtsK+XwNo" +
"8wIgGA5n7ZPfdBi3BdM4VeJWb87WrLlkVxPqeDSbcGrCyMkCIQCqdr+XvADI/UTh" +
"TuQepuErFayJMBSAsNe3NFsw0cUxAQIhAIDGWlcQ+qcLc/yJ/Qb3EeiaonnfWs4m" +
"7MHx821EWbGc";
byte[] keyBytes = Base64.getDecoder().decode(priKeyData.getBytes());
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(keySpec);
}
private static byte[] hashed(String content) throws NoSuchAlgorithmException {
byte[] bytes = content.getBytes();
MessageDigest digest = MessageDigest.getInstance("MD5");
return digest.digest(bytes);
}
private static byte[] sign(RSAPrivateKey pri, byte[] hashed) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
int hashLen = hashed.length;
byte[] prefix = new byte[]{48, 32, 48, 12, 6, 8, 42, -122, 72, -122, -9, 13, 2, 5, 5, 0, 4, 16};
int tLen = prefix.length + hashLen;
int k = (pri.getModulus().bitLength() + 7) / 8;
byte[] em = new byte[k];
em[1] = (byte) 1;
for (int i = 2; i < k - tLen - 1; i++) {
em[i] = (byte) 0xFF;
}
System.arraycopy(prefix, 0, em, k - tLen, prefix.length);
System.arraycopy(hashed, 0, em, k - hashLen, hashLen);
BigInteger m = new BigInteger(em);
byte[] src = m.modPow(pri.getPrivateExponent(), pri.getModulus()).toByteArray();
int numPaddingBytes = em.length - src.length;
for (int i = 0; i < numPaddingBytes; i++) {
em[i] = 0;
}
if (src.length > em.length) {
System.arraycopy(src, 1, em, numPaddingBytes + 1, src.length - 1);
} else {
System.arraycopy(src, 0, em, numPaddingBytes, src.length);
}
return em;
}
private static String byte2HexStr(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
String tmp = Integer.toHexString(b & 0xFF);
sb.append((tmp.length() == 1) ? ("0" + tmp) : tmp);
}
return sb.toString().toUpperCase().trim();
}
}
複製代碼
而後打包,部署。 部署成功後把 IDEA 的激活服務器地址改成你的項目的地址(不帶/rpc),就能夠愉快的激活 IDEA 了。ide
若是實在沒條件本身搭建服務器,能夠用筆者搭建好的激活服務器地址,低調使用,否則可能會被封工具
最後重申一下,不建議你們使用此方法激活,若資金容許,請點擊https://www.jetbrains.com/idea/buy/購買正版,謝謝合做!idea
參考 coding.net/u/chenq_/p/…spa
遷移自個人簡書 2017.09.22