perfectlysoft / perfect-crypto Goto Github PK
View Code? Open in Web Editor NEWCryptographic Operations
License: Apache License 2.0
Cryptographic Operations
License: Apache License 2.0
this is mycode(in my project):
func testCipherString() {
let str = "123456"
let password = "45678"
let salt = "7891"
let result = str.encrypt(Cipher.aes_256_cbc, password: password, salt: salt)
print("result=\(result!)")
guard let str2 = result!.decrypt(Cipher.aes_256_cbc, password: password, salt: salt) else {
print("str2 is nil")
return
}
print("str2 = \(str2)")
}
and the log:
result=-----BEGIN CMS-----
MIAGCSqGSIb3DQEHBqCAMIACAQAwgAYJKoZIhvcNAQcBMB0GCWCGSAFlAwQBKgQQ
4cSbalm6wfgU2gmXJxgVdqCABBBzc6JwEsL221rWXM/oBz/PAAAAAAAAAAAAAA==
-----END CMS-----
str2 is nil
But I added my code to the PerfectCryptoTests.swift
func testCipherString() {
let str = "123456"
let password = "45678"
let salt = "7891"
let result = str.encrypt(Cipher.aes_256_cbc, password: password, salt: salt)
print("result=\(result!)")
guard let str2 = result!.decrypt(Cipher.aes_256_cbc, password: password, salt: salt) else {
print("str2 is nil")
return XCTAssert(false)
}
print("str2 = \(str2)")
XCTAssertEqual(str, str2)
}
test is ok, this log:
Test Case '-[PerfectCryptoTests.PerfectCryptoTests testCipherString]' started.
result=-----BEGIN CMS-----
MIAGCSqGSIb3DQEHBqCAMIACAQAwgAYJKoZIhvcNAQcBMB0GCWCGSAFlAwQBKgQQ
5/NY293XO9NMMtm4nSay7aCABBBeLr0OYPbC8WL4cziMFndeAAAAAAAAAAAAAA==
-----END CMS-----
str2 = 123456
Test Case '-[PerfectCryptoTests.PerfectCryptoTests testCipherString]' passed (0.052 seconds).
I do not know why,help
Thanks.
JWT base64url requires padding '=' chars to be stripped, but some other uses need the '=' to be preserved. An encoding should be added which leaves the = intact, replacing only '+' and '/'.
PerfectCrypto/Keys.swift:61:16: error: cannot find 'EVP_PKEY_base_id' in scope
let typeId = EVP_PKEY_base_id(pkey)
libssl-dev is already the newest version (3.0.2-0ubuntu1.2).
openssl is already the newest version (3.0.2-0ubuntu1.2)
I am using Swift 4.1 binaries from the Ubuntu 16.10 release on Ubuntu 18.04 after downgrading a few system libraries. I can invoke swift
, swift-build
successfully.
We are using Perfect-Crypto as a dependency for a project, but compiling the module fails with the following errors. Note that libssl-dev
and openssl
are installed.
Package: libssl-dev
Version: 1.1.0g-2ubuntu4
Package: openssl
Version: 1.1.0g-2ubuntu4
mkdir -p .build/debug
cp Sources//x264.* .build/debug/
swift build -Xlinker -L/usr/local/lib -Xlinker -lenergymon-default -Xlinker -lx264
Compile Swift Module 'PerfectCrypto' (7 sources)
Compile Swift Module 'Parser' (13 sources)
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:31:33: error: use of undeclared type 'EVP_PKEY'
let pkey: UnsafeMutablePointer<EVP_PKEY>?
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:35:35: error: use of undeclared type 'EVP_PKEY'
init(_ key: UnsafeMutablePointer<EVP_PKEY>?) {
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:71:44: error: use of undeclared type 'EVP_PKEY'
convenience init(kp: UnsafeMutablePointer<EVP_PKEY>?) {
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:64:45: error: use of undeclared type 'BIO'
typealias BIOPointer = UnsafeMutablePointer<BIO>?
^~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:78:48: error: use of undeclared type 'BIO_METHOD'
fileprivate init(method: UnsafeMutablePointer<BIO_METHOD>?) {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:80:32: error: use of undeclared type 'EVP_PKEY'
var kp: UnsafeMutablePointer<EVP_PKEY>? = nil
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:198:32: error: use of undeclared type 'EVP_PKEY'
var kp: UnsafeMutablePointer<EVP_PKEY>?
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:64:45: error: use of undeclared type 'BIO'
typealias BIOPointer = UnsafeMutablePointer<BIO>?
^~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:78:48: error: use of undeclared type 'BIO_METHOD'
fileprivate init(method: UnsafeMutablePointer<BIO_METHOD>?) {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:232:11: error: initializer does not override a designated initializer from its superclass
override init(bio: BIOPointer) {
~~~~~~~~ ^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:210:14: error: 'checkedResult' produces 'Int', not the expected contextual result type 'Int'
return try checkedResult(Int(BIO_write(head, bytes.baseAddress, Int32(bytes.count))))
^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:281:25: error: use of undeclared type 'EVP_MD'
var evp: UnsafePointer<EVP_MD> {
^~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:408:25: error: use of undeclared type 'EVP_CIPHER'
var evp: UnsafePointer<EVP_CIPHER> {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:64:45: error: use of undeclared type 'BIO'
typealias BIOPointer = UnsafeMutablePointer<BIO>?
^~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:78:48: error: use of undeclared type 'BIO_METHOD'
fileprivate init(method: UnsafeMutablePointer<BIO_METHOD>?) {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/Keys.swift:35:35: error: use of undeclared type 'EVP_PKEY'
init(_ key: UnsafeMutablePointer<EVP_PKEY>?) {
^~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:275:30: error: use of undeclared type 'BIO'
func bio() -> UnsafePointer<BIO>? {
^~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:281:25: error: use of undeclared type 'EVP_MD'
var evp: UnsafePointer<EVP_MD> {
^~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:408:25: error: use of undeclared type 'EVP_CIPHER'
var evp: UnsafePointer<EVP_CIPHER> {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:64:45: error: use of undeclared type 'BIO'
typealias BIOPointer = UnsafeMutablePointer<BIO>?
^~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:32:3: error: use of unresolved identifier 'ERR_load_crypto_strings'
ERR_load_crypto_strings()
^~~~~~~~~~~~~~~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:34:3: error: use of unresolved identifier 'OPENSSL_add_all_algorithms_conf'
OPENSSL_add_all_algorithms_conf()
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:36:20: error: use of unresolved identifier 'CRYPTO_num_locks'
for i in 0..<Int(CRYPTO_num_locks()) {
^~~~~~~~~~~~~~~~
COpenSSL.CRYPTO_dynlock:1:15: note: did you mean 'CRYPTO_dynlock'?
public struct CRYPTO_dynlock {
^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:49:3: error: use of unresolved identifier 'CRYPTO_set_locking_callback'
CRYPTO_set_locking_callback(lockingCallback)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:59:3: error: use of unresolved identifier 'CRYPTO_set_id_callback'
CRYPTO_set_id_callback(threadIdCallback)
^~~~~~~~~~~~~~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/ByteIO.swift:78:48: error: use of undeclared type 'BIO_METHOD'
fileprivate init(method: UnsafeMutablePointer<BIO_METHOD>?) {
^~~~~~~~~~
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:304:19: error: use of unresolved identifier 'EVP_MD_CTX_create'
guard let ctx = EVP_MD_CTX_create() else {
^~~~~~~~~~~~~~~~~
COpenSSL.EVP_MD_CTX_free:1:13: note: did you mean 'EVP_MD_CTX_free'?
public func EVP_MD_CTX_free(_ ctx: OpaquePointer!)
^
COpenSSL.EVP_MD_CTX_reset:1:13: note: did you mean 'EVP_MD_CTX_reset'?
public func EVP_MD_CTX_reset(_ ctx: OpaquePointer!) -> Int32
^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:348:19: error: use of unresolved identifier 'EVP_MD_CTX_create'
guard let ctx = EVP_MD_CTX_create() else {
^~~~~~~~~~~~~~~~~
COpenSSL.EVP_MD_CTX_free:1:13: note: did you mean 'EVP_MD_CTX_free'?
public func EVP_MD_CTX_free(_ ctx: OpaquePointer!)
^
COpenSSL.EVP_MD_CTX_reset:1:13: note: did you mean 'EVP_MD_CTX_reset'?
public func EVP_MD_CTX_reset(_ ctx: OpaquePointer!) -> Int32
^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:308:4: error: use of unresolved identifier 'EVP_MD_CTX_destroy'
EVP_MD_CTX_destroy(ctx)
^~~~~~~~~~~~~~~~~~
COpenSSL.EVP_MD_CTX_ctrl:1:13: note: did you mean 'EVP_MD_CTX_ctrl'?
public func EVP_MD_CTX_ctrl(_ ctx: OpaquePointer!, _ cmd: Int32, _ p1: Int32, _ p2: UnsafeMutableRawPointer!) -> Int32
^
COpenSSL.EVP_MD_CTX_reset:1:13: note: did you mean 'EVP_MD_CTX_reset'?
public func EVP_MD_CTX_reset(_ ctx: OpaquePointer!) -> Int32
^
/home/sbiswas/proteus/cp2/.build/checkouts/Perfect-Crypto.git--8520228359058886722/Sources/PerfectCrypto/OpenSSLInternal.swift:352:4: error: use of unresolved identifier 'EVP_MD_CTX_destroy'
EVP_MD_CTX_destroy(ctx)
^~~~~~~~~~~~~~~~~~
COpenSSL.EVP_MD_CTX_ctrl:1:13: note: did you mean 'EVP_MD_CTX_ctrl'?
public func EVP_MD_CTX_ctrl(_ ctx: OpaquePointer!, _ cmd: Int32, _ p1: Int32, _ p2: UnsafeMutableRawPointer!) -> Int32
^
COpenSSL.EVP_MD_CTX_reset:1:13: note: did you mean 'EVP_MD_CTX_reset'?
public func EVP_MD_CTX_reset(_ ctx: OpaquePointer!) -> Int32
^
/home/sbiswas/proteus/cp2/.build/checkouts/swift-ast-1245461573963890367/Sources/Parser/Parser+Declaration.swift:675:27: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
guard rawValueCases.flatMap({ $0.assignment }).isEmpty else {
^
/home/sbiswas/proteus/cp2/.build/checkouts/swift-ast-1245461573963890367/Sources/Parser/Parser+Declaration.swift:675:27: note: use 'compactMap(_:)' instead
guard rawValueCases.flatMap({ $0.assignment }).isEmpty else {
^~~~~~~
compactMap
/home/sbiswas/proteus/cp2/.build/checkouts/swift-ast-1245461573963890367/Sources/Parser/Parser+Declaration.swift:679:26: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
guard unionCases.flatMap({ $0.tuple }).isEmpty else {
^
/home/sbiswas/proteus/cp2/.build/checkouts/swift-ast-1245461573963890367/Sources/Parser/Parser+Declaration.swift:679:26: note: use 'compactMap(_:)' instead
guard unionCases.flatMap({ $0.tuple }).isEmpty else {
^~~~~~~
compactMap
error: terminated(1): /home/sbiswas/software/swift-4.1-RELEASE-ubuntu16.10/usr/bin/swift-build-tool -f /home/sbiswas/proteus/cp2/.build/debug.yaml main output:
OpenSSL is much more prone to vulnerabilities than LibreSSL. Perhaps we can switch to that instead of using an embedded version of OpenSSL? Vapor and Zewo are all using LibreSSL instead of OpenSSL.
Alternatively let the user supply an API-compatible xxxSSL library like what the Swift-NIO team is doing: https://github.com/apple/swift-nio-ssl
I’d love to see support for PKCS#7/Cryptographic Message Syntax added to Perfect-Crypto. It would allow for things like signed/encrypted iOS profiles to be delivered by a Perfect-based REST endpoint. (https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/iPhoneOTAConfiguration/profile-service/profile-service.html#//apple_ref/doc/uid/TP40009505-CH2-SW37). Additionally, it would allow us to replace a HUGE amount of our existing Java code with server-side Swift. I know this functionality is supported by OpenSSL, so it may be easy to incorporate it into Perfect-Crypto.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.