基于DH算法做SM4密钥的交换
in Java with 0 comment

基于DH算法做SM4密钥的交换

in Java with 0 comment

基于DH算法,BC实现SM4密钥的交换

C: Client
S: Server
M,N:提前约定的两个随机数(安全大素数和本原根)
CA: Client端持有的随机整数
SB:Server端持有的随机整数

DH算法

C端逻辑:
 - 生成随机CA  
 - 计算X -> M^CA % N  
 - 将X传递给S
S端逻辑:
 - 生成随机SB  
 - 计算Y -> M^SB % N 
 - 将Y传递个C
C端:DH-C -> Y^CA % N
S端:DH-S -> X^SB % N
DH-C = DH-S

SM4Key生成(BC)

    final Provider provider = ProviderHelper.PROVIDER.getProvider();
    KeyGenerator kg = KeyGenerator.getInstance("SM4", provider);
    kg.init(new SecureRandom(String.valueOf(DH).getBytes()));
    SecretKey keye = kg.generateKey();
    byte[] sm4k = keye.getEncoded();
    System.out.println(new String(sm4k, "UTF-8"));
Comments are closed.