mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-19 22:12:26 +00:00
Signing.
This commit is contained in:
parent
cb259b2657
commit
ebeae2fe7a
@ -13,7 +13,7 @@ extension Stub {
|
|||||||
public var secrets: [Secret] = []
|
public var secrets: [Secret] = []
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
try! create(size: 256)
|
// try! create(size: 256)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func create(size: Int) throws {
|
public func create(size: Int) throws {
|
||||||
@ -32,7 +32,7 @@ extension Stub {
|
|||||||
kSecAttrIsPermanent: true,
|
kSecAttrIsPermanent: true,
|
||||||
kSecAttrAccessControl: access
|
kSecAttrAccessControl: access
|
||||||
]
|
]
|
||||||
] as CFDictionary
|
] as CFDictionary
|
||||||
|
|
||||||
var privateKey: SecKey! = nil
|
var privateKey: SecKey! = nil
|
||||||
var publicKey: SecKey! = nil
|
var publicKey: SecKey! = nil
|
||||||
@ -46,11 +46,23 @@ extension Stub {
|
|||||||
print("Public Key OpenSSH: \(OpenSSHKeyWriter().openSSHString(secret: secret))")
|
print("Public Key OpenSSH: \(OpenSSHKeyWriter().openSSHString(secret: secret))")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func delete(secret: Secret) throws {
|
|
||||||
}
|
|
||||||
|
|
||||||
public func sign(data: Data, with secret: Secret) throws -> Data {
|
public func sign(data: Data, with secret: Secret) throws -> Data {
|
||||||
return Data()
|
let privateKey = SecKeyCreateWithData(secret.privateKey as CFData, [
|
||||||
|
kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
|
||||||
|
kSecAttrKeySizeInBits: secret.keySize,
|
||||||
|
kSecAttrKeyClass: kSecAttrKeyClassPrivate
|
||||||
|
] as CFDictionary
|
||||||
|
, nil)!
|
||||||
|
let signatureAlgorithm: SecKeyAlgorithm
|
||||||
|
switch secret.keySize {
|
||||||
|
case 256:
|
||||||
|
signatureAlgorithm = .ecdsaSignatureMessageX962SHA256
|
||||||
|
case 384:
|
||||||
|
signatureAlgorithm = .ecdsaSignatureMessageX962SHA384
|
||||||
|
default:
|
||||||
|
fatalError()
|
||||||
|
}
|
||||||
|
return SecKeyCreateSignature(privateKey, signatureAlgorithm, data as CFData, nil) as! Data
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user