| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /**
- * RSA加密工具
- *
- * 使用JSEncrypt库进行RSA加密
- */
- import JSEncrypt from 'jsencrypt';
- /**
- * 使用RSA公钥加密数据
- *
- * @param data 要加密的明文数据
- * @param publicKey PEM格式的RSA公钥
- * @returns Base64编码的加密数据
- */
- export function rsaEncrypt(data: string, publicKey: string): string {
- const encrypt = new JSEncrypt();
- encrypt.setPublicKey(publicKey);
-
- const encrypted = encrypt.encrypt(data);
- if (!encrypted) {
- throw new Error('RSA加密失败');
- }
-
- return encrypted;
- }
- /**
- * 加密实名认证数据
- *
- * @param realName 真实姓名
- * @param idCard 身份证号
- * @param publicKey RSA公钥
- * @returns 加密后的数据
- */
- export function encryptVerificationData(
- realName: string,
- idCard: string,
- publicKey: string
- ): string {
- // 组合数据:real_name|id_card
- const combinedData = `${realName}|${idCard}`;
- return rsaEncrypt(combinedData, publicKey);
- }
|