Skip to content
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

aes_256_cbc encrypted results cannot be decrypted #17

Open
a363211861 opened this issue Aug 10, 2018 · 1 comment
Open

aes_256_cbc encrypted results cannot be decrypted #17

a363211861 opened this issue Aug 10, 2018 · 1 comment

Comments

@a363211861
Copy link

a363211861 commented Aug 10, 2018

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.

@sarfraz-ios
Copy link

sarfraz-ios commented Oct 29, 2020

You have initialise the framework once like this
_ = PerfectCrypto.isInitialized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants