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

Having problems while decrypting #174

Closed
lemarian opened this issue Nov 2, 2015 · 2 comments
Closed

Having problems while decrypting #174

lemarian opened this issue Nov 2, 2015 · 2 comments

Comments

@lemarian
Copy link

lemarian commented Nov 2, 2015

While decrypting I get the error : The operation couldnot be performed RNCryptorError 1
I dont understand what I am doing wrong. Here is my block of code
screen shot 2015-11-02 at 4 20 11 pm

@rnapier
Copy link
Member

rnapier commented Nov 2, 2015

Please just post code into the question rather than a screenshot. I can't compile a screenshot, and they're very hard to read.

Error 1 is an HMAC error. Either your data is corrupted or your password is incorrect. Most likely, the data in encodedData is not precisely the data that came out of the encryptor. You should verify that it is.

Note that NSException never makes sense in Swift. Switch can't catch them. They only make sense in ObjC if you're going to crash the program shortly after. They're not memory-safe in ObjC. You meant to use Swift's throw and ErrorType, which are unrelated to raise or NSException.

@rnapier rnapier closed this as completed in ae6bbec Nov 2, 2015
@lemarian
Copy link
Author

lemarian commented Nov 3, 2015

This is my code and I get error 1

class func decrypt(message: String) -> String {
print("the message to decrypt is (message)")
let data1: NSData = NSData(base64EncodedString: message, options: NSDataBase64DecodingOptions(rawValue: 0))!

    do {

        let decData : NSData = try RNCryptor.decryptData(data1, password: password)
        print("The decrypted data is now now \(decData)")

        let tokenString: String  = NSString(data: decData, encoding: NSUTF8StringEncoding)! as String
        return tokenString

    }
    catch let error as NSError {
        print("The error description is \(error.localizedDescription)")
        print("The main error is \(error.description)")
        debugPrint("The main main main eror :\(error)")

        return ""
    }

}

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