java 音乐api接口_关于网易云音乐爬虫的api接口?

java 版本的网易 api 加密方式:

加密工具类

https://github.com/junbaor/netease/blob/master/src/main/java/com/junbaor/netease/common/EncryptUtils.java

调用测试类

https://github.com/junbaor/netease/blob/master/src/test/java/com/junbaor/netease/common/TestApi.java

希望对你有所帮助。

package com.junbaor.netease.common;

import org.apache.commons.lang3.RandomStringUtils;

import sun.misc.BASE64Encoder;

import javax.crypto.Cipher;

import javax.crypto.spec.IvParameterSpec;

import javax.crypto.spec.SecretKeySpec;

import java.math.BigInteger;

import java.util.HashMap;

import java.util.Map;

public class EncryptUtils {

private final static String modulus = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7" +

"b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280" +

"104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932" +

"575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b" +

"3ece0462db0a22b8e7";

private final static String nonce = "0CoJUm6Qyw8W8jud";

private final static String pubKey = "010001";

private static final String PARAMS = "params";

private static final String ENCSECKEY = "encSecKey";

public static Map encrypt(String text) {

String secKey = RandomStringUtils.random(16, "0123456789abcde");

String encText = aesEncrypt(aesEncrypt(text, nonce), secKey);

String encSecKey = rsaEncrypt(secKey, pubKey, modulus);

Map map = new HashMap();

map.put(PARAMS, encText);

map.put(ENCSECKEY, encSecKey);

return map;

}

private static String aesEncrypt(String text, String key) {

try {

IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes("UTF-8"));

SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);

byte[] encrypted = cipher.doFinal(text.getBytes());

return new BASE64Encoder().encode(encrypted);

} catch (Exception e) {

return "";

}

}

private static String rsaEncrypt(String text, String pubKey, String modulus) {

text = new StringBuilder(text).reverse().toString();

BigInteger rs = new BigInteger(String.format("%x", new BigInteger(1, text.getBytes())), 16)

.modPow(new BigInteger(pubKey, 16), new BigInteger(modulus, 16));

String r = rs.toString(16);

if (r.length() >= 256) {

return r.substring(r.length() - 256, r.length());

} else {

while (r.length() < 256) {

r = 0 + r;

}

return r;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值