1. 2024-02-04立春。立春,为二十四节气之首。立,是“开始”之意;春,代表着温暖、生长。时至立春,在我国的北回归线(黄赤交角)及其以南一带,可明显感觉到早春的气息。北回归线是一条重要纬线,其自西向东穿过中国云南、广西、广东、福建(海域)、台湾五省区。
《立春》 宋·白玉蟾
东风吹散梅梢雪,一夜挽回天下春。
从此阳春应有脚,百花富贵草精神。
《立春偶成》宋·张栻
律回岁晚冰霜少,春到人间草木知。
便觉眼前生意满,东风吹水绿参差。
2. 计算cookie的算法
导入必要的jar包
<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.18</version> </dependency>
代码
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.asymmetric.KeyType; import cn.hutool.crypto.asymmetric.RSA; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.security.Key; /** <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.18</version> </dependency> **/ public class SecretUtil { static final String publicKey = "我的公钥,用于加密"; public static void main(String[] args) throws Exception { String userName = "用户名"; String keyStr = "密码"; String generatedCookieValue = encryptRC4ToString(keyStr.toUpperCase(), userName); // 用密码的大写形式对userName进行RC4对称加密 System.out.println(generatedCookieValue); System.out.println(decryptRC4(keyStr.toUpperCase(), generatedCookieValue)); // 用密码的大写形式对userName加密后的String进行RC4对称解密,因为RC4是对称加密,所以解密时也用相同的密钥进行解密 System.out.println(ecryptRSAByPublicKey(keyStr, publicKey)); // 用publicKey对密码进行RSA非对称加密 } private static String ecryptRSAByPublicKey(String textPasswd, String encPublicKey) { // 用encPublicKey对texyPassword进行RSA加密 因为是非对称加密,解密需要用私钥,我这里不知道私钥,所以不知道怎么解密。 RSA rsa = SecureUtil.rsa(null, encPublicKey); return rsa.encryptBase64(textPasswd.getBytes(), KeyType.PublicKey); } public static String encryptRC4ToString(String key, String plaintext) { try { byte[] encrypted = encryptRC4(key, plaintext); return bytesToHex(encrypted); } catch (Exception e) { e.printStackTrace(); } return null; } private static byte[] encryptRC4(String key, String plaintext) throws Exception { Cipher rc4 = Cipher.getInstance("RC4"); Key secretKey = new SecretKeySpec(key.getBytes(), "RC4"); rc4.init(Cipher.ENCRYPT_MODE, secretKey); return rc4.doFinal(plaintext.getBytes()); } private static String decryptRC4(String key, String text) throws Exception { Cipher rc4 = Cipher.getInstance("RC4"); Key secretKey = new SecretKeySpec(key.getBytes(), "RC4"); rc4.init(Cipher.DECRYPT_MODE, secretKey); byte[] decryptedBytes = rc4.doFinal(hexToBytes(text)); return new String(decryptedBytes); } private static String bytesToHex(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(String.format("%02x", b)); } return sb.toString(); } private static byte[] hexToBytes(String hexString) { int len = hexString.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); } return data; } }
标签:02,25,String,04,RC4,hutool,Cipher,static,byte From: https://www.cnblogs.com/panda4671/p/18006698