黎星凯
2024-05-17 3520e86e2b00b9c1ee3f4fffd4ab49fe3d6c259e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.iplatform.security;
 
import com.iplatform.base.util.PlatformRSAUtils;
import com.walker.infrastructure.utils.Base64;
import com.walker.infrastructure.utils.Base64Utils;
import com.walker.infrastructure.utils.RSAUtil;
import org.junit.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
 
public class TestSecurity {
 
//    @Test
    public void testDecryptPassword() throws Exception{
        String encodePass = "DOEUaXiOa0y8Kq0De+P4OL/bdydlEFC+330I2lmXbz8VwHJYugLV/IPeXp31fZ5yOQvelMLwDutNtgQaRVS9L8n5ctjpYQZC3HAVDZ+6sXhE3TIH14Q8S3RhD3kE8iBVKrWd7423iCjflNwUPedFcQ0zVpJt3pC3wvDUayXIJnI=";
//        String decode = Base64.decodeBase64(encode.getBytes(StandardCharsets.UTF_8));
 
        byte[] keyBytes = Base64Utils.decode(PlatformRSAUtils.PRIK);
        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec);
 
        String password = RSAUtil.decrypt(privateK, Base64.decode(encodePass.getBytes()));
        System.out.println(password);
    }
 
//    @Test
    public void testGeneratePassword(){
        String raw = "123456";
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String encrypt = passwordEncoder.encode(raw);
        System.out.println("encrypt = " + encrypt);
    }
}