手动修改,增加 mac 校验密钥对
This commit is contained in:
parent
56b0ea8138
commit
22ca568e88
@ -13,8 +13,8 @@ public class Main {
|
||||
private static final String PUBLIC_KEY_FILE = DEVICE_DIR + "/dev.fingerprint.pub";
|
||||
private static final String PUBLIC_KEY_SM3_FILE = DEVICE_DIR + "/dev.fingerprint.pub.sm3";
|
||||
private static final String FINGERPRINT_DATA_FILE = DEVICE_DIR + "/dev.fingerprint.data";
|
||||
private static final String PRIVATE_KEY_PATH = "/sm2_private_key.pem";
|
||||
private static final String PUBLIC_KEY_PATH = "/sm2_public_key.pem";
|
||||
private static final String FINGERPRINT_PRIVATE_KEY_PATH = "/fingerprint.sm2_private_key.pem";
|
||||
private static final String FINGERPRINT_PUBLIC_KEY_PATH = "/fingerprint.sm2_public_key.pem";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
@ -119,10 +119,10 @@ public class Main {
|
||||
String plainText = buildPlainText(fingerprint);
|
||||
System.out.println("\n拼接后的原文: " + plainText);
|
||||
|
||||
byte[] signature = SM2Util.sign(plainText.getBytes(StandardCharsets.UTF_8), PRIVATE_KEY_PATH);
|
||||
byte[] signature = SM2Util.sign(plainText.getBytes(StandardCharsets.UTF_8), FINGERPRINT_PRIVATE_KEY_PATH);
|
||||
System.out.println("签名结果(Base64): " + Base64.getEncoder().encodeToString(signature));
|
||||
|
||||
PublicKey publicKey = SM2Util.loadPublicKey(PUBLIC_KEY_PATH);
|
||||
PublicKey publicKey = SM2Util.loadPublicKey(FINGERPRINT_PUBLIC_KEY_PATH);
|
||||
String publicKeyPEM = SM2Util.publicKeyToPEM(publicKey);
|
||||
|
||||
SM3Util.writeFile(SIGN_FILE, signature);
|
||||
@ -166,7 +166,7 @@ public class Main {
|
||||
System.out.println("保存的拼接原文: " + savedPlainText);
|
||||
|
||||
byte[] signature = SM3Util.readFileBytes(SIGN_FILE);
|
||||
PublicKey publicKey = SM2Util.loadPublicKey(PUBLIC_KEY_PATH);
|
||||
PublicKey publicKey = SM2Util.loadPublicKey(FINGERPRINT_PUBLIC_KEY_PATH);
|
||||
|
||||
boolean dataMatch = plainText.equals(savedPlainText);
|
||||
boolean signatureVerified = SM2Util.verify(savedPlainText.getBytes(StandardCharsets.UTF_8), signature, publicKey);
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgh9tzISMZY6ob2KVM
|
||||
0Am9+Zm2jG+CLhp+g72hN3t7dl2gCgYIKoEcz1UBgi2hRANCAAT+73yu5EIYMSjc
|
||||
60mEZXmYpR2O8yTWOY4WmG1eZqKhB/46DarhZVN8AAvpOYohZ1l3luk26jnpQNYx
|
||||
psC8QVu5
|
||||
-----END PRIVATE KEY-----
|
||||
@ -0,0 +1,4 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE/u98ruRCGDEo3OtJhGV5mKUdjvMk
|
||||
1jmOFphtXmaioQf+Og2q4WVTfAAL6TmKIWdZd5bpNuo56UDWMabAvEFbuQ==
|
||||
-----END PUBLIC KEY-----
|
||||
@ -25,13 +25,13 @@ public class SM2UtilTest {
|
||||
resourcesDir.mkdirs();
|
||||
}
|
||||
|
||||
File privateKeyFile = new File(resourcesPath + "/sm2_private_key.pem");
|
||||
File privateKeyFile = new File(resourcesPath + "/mac_sm2_private_key.pem");
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(privateKeyFile), StandardCharsets.UTF_8)) {
|
||||
writer.write(privateKeyPEM);
|
||||
}
|
||||
System.out.println("Private key saved to: " + privateKeyFile.getAbsolutePath());
|
||||
|
||||
File publicKeyFile = new File(resourcesPath + "/sm2_public_key.pem");
|
||||
File publicKeyFile = new File(resourcesPath + "/mac_sm2_public_key.pem");
|
||||
try (Writer writer = new OutputStreamWriter(new FileOutputStream(publicKeyFile), StandardCharsets.UTF_8)) {
|
||||
writer.write(publicKeyPEM);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user