不建议大家使用此方法激活,若资金允许,请点击https://www.jetbrains.com/idea/buy/购买正版,谢谢合作!
前言
用过 IDEA 的同学应该都知道,这个软件是收费的,对于笔者来说是很贵了,因此只能另寻他法。 我们可以很轻松的从网上找到搭建本地激活服务器的教程,但是每次打开 IDEA 都要先打开激活服务器,太麻烦。 或者从网上找别人搭建好的激活服务器,但是可能某一天突然就用不了了,所以如果有条件还是自己搭建一个激活服务器比较靠谱。
要求
一台可以远程访问的主机 一个 Spring web 项目
动手
打开我们的 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);
- }
- }
- 复制代码
添加工具类
- 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 了。
福利
如果实在没条件自己搭建服务器,可以用笔者搭建好的激活服务器地址,低调使用,不然可能会被封
最后重申一下,不建议大家使用此方法激活,若资金允许,请点击https://www.jetbrains.com/idea/buy/购买正版,谢谢合作!
迁移自我的简书 2017.09.22