RNCryptor / RNCryptor

CCCryptor (AES encryption) wrappers for iOS and Mac in Swift. -- For ObjC, see RNCryptor/RNCryptor-objc
https://groups.google.com/forum/#!forum/rncryptor
MIT License
3.36k stars 523 forks source link

Decrypting from RNCryptor-cs on swift 3 and RNCryptor gives me unknown header #263

Closed RBabb closed 6 years ago

RBabb commented 6 years ago

I have a string that I encrypted using RNCryptor-cs and trying to decrypt it on mac osx using RNCryptor decrypt but not having much luck. swift:

public func decrypt(ciphertext: String) -> String {
        do {
            let data = Data(base64Encoded: ciphertext)
            let originalData = try RNCryptor.decrypt(data: data!, withPassword: self.Salt)
            return String(data: originalData, encoding: .utf8)! as String
        } catch {
            self.recordLog(fileName: "error", Msg: "\(error)", Fnc: "decrypt")
            return ""
        }
    }

C#

static public string Encrypt(string strText)
        {
            try
            {
                return new Encryptor().Encrypt(strText, Salt);
            }
            catch (Exception e)
            {
                RecordLog("error", e.Message, "Tools:::Encrypt");
                return string.Empty;
            }
        }

Are they not compatible? Any suggestions how I can make it work? Or maybe I'm just having a bald moment. Any direction would be appreciated. Thank you.

RBabb commented 6 years ago

respectively it works from MAC encrypt to PC decrypt but not PC encrypt to mac decrypt

rnapier commented 6 years ago

What error are you receiving? Do you have an example of the output?

RBabb commented 6 years ago

I am getting null output. And an error of unknown header. The salt (password) is the same. The only thing I think could be the issue is the ivlength.

On Wed, Dec 13, 2017 at 18:53 Rob Napier notifications@github.com wrote:

What error are you receiving? Do you have an example of the output?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RNCryptor/RNCryptor/issues/263#issuecomment-351563279, or mute the thread https://github.com/notifications/unsubscribe-auth/AE15dmsST-URxxpgZrm94Z3Tmx9sBfg4ks5tAGNsgaJpZM4Q-PaE .

-- Regards, Bob Babb National Solutions Integration Manager Web & Multichannel Marketing Solutions & Analytics Konica Minolta Business Solutions U.S.A., Inc. Office: (215) 293-1428 <javascript:void(0);> Mobile: (470) 779-2200 <javascript:void(0);> Twitter: @rbabb_kmbs http://twitter.com/rbabb_kmbs Visit us: Count on Konica Minolta http://www.countonkonicaminolta.com/ http://www.facebook.com/konicaminoltaus http://www.twitter.com/konicaminoltaus https://plus.google.com/u/0/101069343240482341568/about http://www.linkedin.com/companies/4830 http://www.youtube.com/user/konicaminoltaus http://www.pinterest.com/konicaminoltaus Disclaimer http://kmbs.konicaminolta.us/signature/KMBSUS-Disclaimer%20.png

rnapier commented 6 years ago

"Unknown header" means that the data you're passing isn't in RNCryptor format. That usually means it's encoded somehow (like Base64). The first byte of the data you're passing to decrypt should be 03.

RBabb commented 6 years ago

Found the issue.... It was in the RnCryptor-cs the default schema was version 2 changed private Schema defaultSchemaVersion = Schema.V2; to private Schema defaultSchemaVersion = Schema.V3; and all is well. Thanks.