package sdf; import com.sunyard.chsm.WebServerApp; import com.sunyard.chsm.enums.KeyAlg; import com.sunyard.chsm.sdf.BCSdfApiService; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.Random; @Slf4j @SpringBootTest(classes = WebServerApp.class) public class BCSdfApiServiceTest { @Autowired private BCSdfApiService bcSdfApiService; // 对称加密解密测试 @Test void testSym() { byte[] data = new byte[128]; new Random().nextBytes( data ); byte[] key = bcSdfApiService.genSymKey( KeyAlg.SM4 ); byte[] enData = bcSdfApiService.symEncrypt( KeyAlg.SM4, key, data ); byte[] deData = bcSdfApiService.symDecrypt( KeyAlg.SM4, key, enData ); Assert.assertArrayEquals( data, deData ); } }