Added support to sign messages

This commit is contained in:
Christian Risi
2024-12-02 20:01:07 +01:00
parent 0eb4c0069e
commit 84c1058e83
6 changed files with 78 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
import Testing
import RandomCpp
import Foundation
import SwiftASN1
import Crypto
@testable import IoT_Simulator_Core
@@ -38,9 +38,10 @@ import SwiftASN1
let keyPath = "./Private/privateKey.pem"
let key = try pem2key(filePath: keyPath)
let obj = [1, 2, 3]
let obj = "[1, 2, 3] "
let signature = try sign(object: obj, key: key)
let signature = try sign(string: obj, key: key)
print(signature)
}
@@ -49,10 +50,14 @@ import SwiftASN1
let keyPath = "./Private/privateKey.pem"
let key = try pem2key(filePath: keyPath)
let obj = "[1, 2, 3]"
let obj = "[1, 2, 3] "
let signature = try sign(object: obj, key: key)
let signature = try sign(string: obj, key: key)
let puKey = key.publicKey
let verify = try verify(signature: signature, string: obj, key: puKey)
print(verify)
assert(verify)
}