New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use #25
Comments
I've wrote test code just like this. import XCTest
import Foundation
@testable import myApp
let keyPair = try? myAppSwiftTests.createKeyPair(2048)
let plainText = "Hello, world!"
class myAppSwiftTests: XCTestCase {
override func setUp() {
super.setUp()
self.continueAfterFailure = false
}
override func tearDown() {
super.tearDown()
}
static func createKeyPair(_ size: Int) throws -> (Data, Data) {
return try CC.RSA.generateKeyPair(size)
}
func testRsaKeyPairGeneration(){
self.measure{
let (priv, pub) = keyPair!
XCTAssertNotNil(priv)
XCTAssertNotNil(pub)
}
}
func testRsaPublicKeyEncryption(){
let (_, publicKey) = keyPair!
let testData = plainText.data(using: String.Encoding.utf8)!
var encrypted: Data? = nil
self.measure {
encrypted = try? CC.RSA.encrypt(testData, derKey: publicKey, tag: Data(), padding: .pkcs1, digest: .sha256)
}
XCTAssertNotNil(encrypted)
}
func testRsaPrivateKeyDecryption(){
let (privateKey, publicKey) = keyPair!
let testData = plainText.data(using: String.Encoding.utf8)!
var encrypted: Data? = nil
var decrypted: (Data, Int)? = nil
self.measure {
encrypted = try? CC.RSA.encrypt(testData, derKey: publicKey, tag: Data(), padding: .pkcs1, digest: .sha256)
decrypted = try? CC.RSA.decrypt(encrypted!, derKey: privateKey, tag: Data(), padding: .pkcs1, digest: .sha256)
}
XCTAssertNotNil(encrypted)
XCTAssertNotNil(decrypted)
XCTAssertNotNil(decrypted!.0)
XCTAssertEqual(String(data: decrypted!.0, encoding: .utf8), plainText)
}
} |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, everyone!
Can you please help me to use SwCrypt?
The task is to:
To be honest, I'm new in cryptography and know a little about it's principles. Are actions mentioned above possible?
I've read all the issues and still can't get how to use the library.
I've generated public and private keys with.
let (privateKey, publicKey) = try! CC.RSA.generateKeyPair(512)
let privKeyStr = privateKey.base64EncodedString()
let pubKeyStr = publicKey.base64EncodedString()
I have a string which i want to encode and than decode
let testString: String = "Test string"
Trying to encode it:
let testStringData = testString.data(using: .utf8)!
let pubKeyData = pubKeyStr.data(using: .utf8)!
let tagStr = "L" //still can't get what should I use there
let tag = tagStr.data(using: .utf8)!
let encryptedData = try! CC.RSA.encrypt(testStringData, derKey: pubKeyData, tag: tag, padding: .oaep, digest: .sha1)
Get an error:
Can you please help me to use the library?
Thanks!
The text was updated successfully, but these errors were encountered: