Giter Site home page Giter Site logo

rncryptor-objc's Introduction

RNCryptor

BuddyBuild

Cross-language AES Encryptor/Decryptor data format.

The primary targets are Swift and Objective-C, but implementations are available in C, C++, C#, Erlang, Go, Haskell, Java, PHP, Python, Javascript, Ruby, and Dart.

The data format includes all the metadata required to securely implement AES encryption, as described in "Properly encrypting with AES with CommonCrypto," and iOS 6 Programming Pushing the Limits, Chapter 15. Specifically, it includes:

  • AES-256 encryption
  • CBC mode
  • Password stretching with PBKDF2
  • Password salting
  • Random IV
  • Encrypt-then-hash HMAC

Contents

Format Versus Implementation

The RNCryptor data format is cross-platform and there are many implementations. The framework named "RNCryptor" is a specific implementation for Swift and Objective-C. Both have version numbers. The current data format is v3. The current framework implementation (which reads the v3 format) is v4.

Basic Password Usage

// Encryption
let data: NSData = ...
let password = "Secret password"
let ciphertext = RNCryptor.encrypt(data: data, withPassword: password)

// Decryption
do {
    let originalData = try RNCryptor.decrypt(data: ciphertext, withPassword: password)
    // ...
} catch {
    print(error)
}

Incremental Usage

RNCryptor supports incremental use, for example when using with NSURLSession. This is also useful for cases where the encrypted or decrypted data will not comfortably fit in memory.

To operate in incremental mode, you create an Encryptor or Decryptor, call updateWithData() repeatedly, gathering its results, and then call finalData() and gather its result.

//
// Encryption
//
let password = "Secret password"
let encryptor = RNCryptor.Encryptor(password: password)
let ciphertext = NSMutableData()

// ... Each time data comes in, update the encryptor and accumulate some ciphertext ...
ciphertext.appendData(encryptor.updateWithData(data))

// ... When data is done, finish up ...
ciphertext.appendData(encryptor.finalData())

//
// Decryption
//
let password = "Secret password"
let decryptor = RNCryptor.Decryptor(password: password)
let plaintext = NSMutableData()

// ... Each time data comes in, update the decryptor and accumulate some plaintext ...
try plaintext.appendData(decryptor.updateWithData(data))

// ... When data is done, finish up ...
try plaintext.appendData(decryptor.finalData())

Importing into Swift

Most RNCryptor symbols are nested inside an RNCryptor namespace.

Installation

Requirements

RNCryptor 5 is written in Swift 3 and does not bridge to Objective-C (it includes features that are not available). If you want an ObjC implementation, see RNCryptor-objc. That version can be accessed from Swift, or both versions can coexist in the same project.

The Bridging Header

CommonCrypto is not a modular header (and Apple has suggested it may never be). This makes it very challenging to import into Swift. To work around this, the necessary header files have been copied into RNCryptor.h, which needs to be bridged into Swift. You can do this either by using RNCryptor as a framework, adding #import "RNCryptor/RNCryptor.h" to your existing bridging header, or making RNCryptor/RNCryptor.h your bridging header in Build Settings, "Objective-C Bridging Header."

Installing Manually

The easiest way to use RNCryptor is by making it part of your project, without a framework. RNCryptor is just one swift file and one bridging header, and you can skip all the complexity of managing frameworks this way. It also makes version control very simple if you use submodules, or checkin specific versions of RNCryptor to your repository.

This process works for most targets: iOS and OS X GUI apps, Swift frameworks, and OS X commandline apps. It is not safe for ObjC frameworks or frameworks that may be imported into ObjC, since it would cause duplicate symbols if some other framework includes RNCryptor.

  • Drag and link RNCryptor/RNCryptor.swift and RNCryptor.h into your project
  • If you already have a bridging header file, add #import "RNCryptor.h" (or the path to which you copied RNCryptor.h).
  • If you don't have a bridging header:
    • Swift project: In your target's Build Settings, set "Objective-C Bridging Header" to your path for RNCryptor.h. (Or create a bridiging header and follow instructions above.)
    • ObjC project: Xcode will ask if you want to create a bridging header. Allow it to, and add #import "RNCryptor.h" to the header (or the path to which you copied RNCryptor.h)
  • To access RNCryptor from Swift, you don't need to import anything. It's just part of your module.
  • To access RNCryptor from ObjC, import your Swift header (modulename-Swift.h). For example: #import "MyApp-Swift.h".

Built this way, you don't need to (and can't) import RNCryptor into your code. RNCryptor will be part of your module.

github "RNCryptor/RNCryptor" ~> 5.0

This approach will not work for OS X commandline apps. Don't forget to embed RNCryptor.framework.

Built this way, you should add @import RNCryptor; to your ObjC or import RNCryptor to your Swift code.

This approach will not work for OS X commandline apps.

pod 'RNCryptor', '~> 5.0'

This approach will not work for OS X commandline apps.

Built this way, you should add import RNCryptor to your Swift code.

dependencies: [
    .package(url: "https://github.com/RNCryptor/RNCryptor.git", .upToNextMajor(from: "5.0.0"))
]

Swift Package Manager support requires Xcode 12.5 or higher.

Built this way, you should add import RNCryptor to your Swift code.

Advanced Usage

Version-Specific Cryptors

The default RNCryptor.Encryptor is the "current" version of the data format (currently v3). If you're interoperating with other implementations, you may need to choose a specific format for compatibility.

To create a version-locked cryptor, use RNCryptor.EncryptorV3 and RNCryptor.DecryptorV3.

Remember: the version specified here is the format version, not the implementation version. The v4 RNCryptor framework reads and writes the v3 RNCryptor data format.

Key-Based Encryption

You need a little expertise to use key-based encryption correctly, and it is very easy to make insecure systems that look secure. The most important rule is that keys must be random across all their bytes. If you're not comfortable with basic cryptographic concepts like AES-CBC, IV, and HMAC, you probably should avoid using key-based encryption.

Cryptography works with keys, which are random byte sequences of a specific length. The RNCryptor v3 format uses two 256-bit (32-byte) keys to perform encryption and authentication.

Passwords are not "random byte sequences of a specific length." They're not random at all, and they can be a wide variety of lengths, very seldom exactly 32. RNCryptor defines a specific and secure way to convert passwords into keys, and that is one of it's primary features.

Occasionally there are reasons to work directly with random keys. Converting a password into a key is intentionally slow (tens of milliseconds). Password-encrypted messages are also a 16 bytes longer than key-encrypted messages. If your system encrypts and decrypts many short messages, this can be a significant performance impact, particularly on a server.

RNCryptor supports direct key-based encryption and decryption. The size and number of keys may change between format versions, so key-based cryptors are version-specific.

In order to be secure, the keys must be a random sequence of bytes. See Converting a Password to a Key for how to create random sequences of bytes if you only have a password.

let encryptor = RNCryptor.EncryptorV3(encryptionKey: encryptKey, hmacKey: hmacKey)
let decryptor = RNCryptor.DecryptorV3(encryptionKey: encryptKey, hmacKey: hmacKey)

FAQ

How do I detect an incorrect password?

If you decrypt with the wrong password, you will receive an HMACMismatch error. This is the same error you will receive if your ciphertext is corrupted.

The v3 data format has no way to detect incorrect passwords directly. It just decrypts gibberish, and then uses the HMAC (a kind of encrypted hash) to determine that the result is corrupt. You won't discover this until the entire message has been decrypted (during the call to finalData()).

This can be inconvenient for the user if they have entered the wrong password to decrypt a very large file. If you have this situation, the recommendation is to encrypt some small, known piece of data with the same password. Test the password on the small ciphertext before decrypting the larger one.

The v4 data format will provide a faster and more useful mechanism for validating the password or key.

What is an "HMAC Error?" (Error code 1)

See previous question. Either your data is corrupted or you have the wrong password.

The most common cause of this error (if your password is correct) is that you have misunderstood how Base64 encoding works while transferring data to or from the server. If you have a string like "YXR0YWNrIGF0IGRhd24=", this is not "data." This is a string. It is probably Base64 encoded, which is a mechanism for converting data into strings. Some languages (JavaScript, PHP) have a habit of implicitly converting between data into Base64 strings, which is confusing and error-prone (and the source of many of these issues). Simple rule: if you can print it out without your terminal going crazy, it's not encrypted data.

If you convert a Base64-encoded string to data using dataUsingEncoding(), you will get gibberish as far as RNCryptor is concerned. You need to use init?(base64EncodedData:options:). Depending on the options on the iOS side or the server side, spaces and newlines may matter. You need to verify that precisely the bytes that came out of the encryptor are the bytes that go into the decryptor.

Can I use RNCryptor to read and write my non-RNCryptor data format?

No. RNCryptor implements a specific data format. It is not a general-purpose encryption library. If you have created your own data format, you will need to write specific code to deal with whatever you created. Please make sure the data format you've invented is secure. (This is much harder than it sounds.)

If you're using the OpenSSL encryption format, see RNOpenSSLCryptor.

Can I change the parameters used (algorithm, iterations, etc)?

No. See previous question. The v4 format will permit some control over PBKDF2 iterations, but the only thing configurable in the v3 format is whether a password or key is used. This keeps RNCryptor implementations dramatically simpler and interoperable.

How do I manually set the IV?

You don't. See the last two questions.

Also note that if you ever reuse a key+IV combination, you risk attackers decrypting the beginning of your message. A static IV makes a key+IV reuse much more likely (guarenteed if you also have a static key). Wikipedia has a quick overview of this problem.

How do I encrypt/decrypt a string?

AES encrypts bytes. It does not encrypt characters, letters, words, pictures, videos, cats, or ennui. It encrypts bytes. You need to convert other things (such as strings) to and from bytes in a consistent way. There are several ways to do that. Some of the most popular are UTF-8 encoding, Base-64 encoding, and Hex encoding. There are many other options. There is no good way for RNCryptor to guess which encoding you want, so it doesn't try. It accepts and returns bytes in the form of NSData.

To convert strings to data as UTF-8, use dataUsingEncoding() and init(data:encoding:). To convert strings to data as Base-64, use init(base64EncodedString:options:) and base64EncodedStringWithOptions().

Does RNCryptor support random access decryption?

The usual use case for this is encrypting media files like video. RNCryptor uses CBC encryption, which prevents easy random-access. While other modes are better for random-access (CTR for instance), they are more complicated to implement correctly and CommonCrypto doesn't support using them for random access anyway.

It would be fairly easy to build a wrapper around RNCryptor that allowed random-access to blocks of some fixed size (say 64k), and that might work well for video with modest overhead (see inferno for a similar idea in C#). Such a format would be fairly easy to port to other platforms that already support RNCryptor.

If there is interest, I may eventually build this as a separate framework.

See also Issue #161 for a much longer discussion of this topic.

Design Considerations

RNCryptor has several design goals, in order of importance:

Easy to use correctly for most common use cases

The most critical concern is that it be easy for non-experts to use RNCryptor correctly. A framework that is more secure, but requires a steep learning curve on the developer will either be not used, or used incorrectly. Whenever possible, a single line of code should "do the right thing" for the most common cases.

This also requires that it fail correctly and provide good errors.

Reliance on CommonCryptor functionality

RNCryptor has very little "security" code. It relies as much as possible on the OS-provided CommonCryptor. If a feature does not exist in CommonCryptor, then it generally will not be provided in RNCryptor.

Best practice security

Wherever possible within the above constraints, the best available algorithms are applied. This means AES-256, HMAC+SHA256, and PBKDF2. (Note that several of these decisions were reasonable for v3, but may change for v4.)

  • AES-256. While Bruce Schneier has made some interesting recommendations regarding moving to AES-128 due to certain attacks on AES-256, my current thinking is in line with Colin Percival. PBKDF2 output is effectively random, which should negate related-keys attacks against the kinds of use cases we're interested in.

  • AES-CBC mode. This was a somewhat complex decision, but the ubiquity of CBC outweighs other considerations here. There are no major problems with CBC mode, and nonce-based modes like CTR have other trade-offs. See "Mode changes for RNCryptor" for more details on this decision.

  • Encrypt-then-MAC. If there were a good authenticated AES mode on iOS (GCM for instance), I would probably use that for its simplicity. Colin Percival makes good arguments for hand-coding an encrypt-then-MAC rather than using an authenticated AES mode, but in RNCryptor mananging the HMAC actually adds quite a bit of complexity. I'd rather the complexity at a more broadly peer-reviewed layer like CommonCryptor than at the RNCryptor layer. But this isn't an option, so I fall back to my own Encrypt-than-MAC.

  • HMAC+SHA256. No surprises here.

  • PBKDF2. While bcrypt and scrypt may be more secure than PBKDF2, CommonCryptor only supports PBKDF2. NIST also continues to recommend PBKDF2. We use 10k rounds of PBKDF2 which represents about 80ms on an iPhone 4.

Code simplicity

RNCryptor endeavors to be implemented as simply as possible, avoiding tricky code. It is designed to be easy to read and code review.

Performance

Performance is a goal, but not the most important goal. The code must be secure and easy to use. Within that, it is as fast and memory-efficient as possible.

Portability

Without sacrificing other goals, it is preferable to read the output format of RNCryptor on other platforms.

License

Except where otherwise indicated in the source code, this code is licensed under the MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```

rncryptor-objc's People

Contributors

armenm avatar bassrock avatar carllindberg avatar csteynberg avatar danielvy avatar doradiology avatar gabceb avatar guysung avatar kaioelfke avatar klaaspieter avatar kvangork avatar madsolar8582 avatar mkhon avatar rnapier avatar slaunchaman avatar steipete avatar testzugang avatar timestretch avatar tyrone-sudeium avatar vphamdev avatar yeahphil avatar ykalchevskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rncryptor-objc's Issues

Xcode 9 & iOS 11 beta issue

Hi ,
I have issue in RNCryptor.m file
RNCryptor.m:61:12: Conflicting types for 'SecRandomCopyBytes'
I am using pod 'RNCryptor-objc' .
My App is crashing becasue fo this issue .
Please let me know when do we have fix for this.

Thanks,
Venkat

Need synchronous addData: and finish in the decrypt

I already replied with this in my issue asking about ObjC support in the Swift 5.0 RNCryptor, but the Swift one had decryption that happened synchronously. We need that in the ObjC version as well. I've temporarily done it in my local copy of the code but would defer to an appropriate implementation done in the style of the implementor.

Support for SPM

How can I import this using SPM in a objc project? Seems like Package.swift file is missing

How do I decrypt using a third party AES-CBC decryptor?

So far, I've been able to encrypt and decrypt nicely in iOS using this RNCryptor lib. But, the trouble comes when decryption needs to happen outside of the iOS playground. Here's what I've tried so far:

password
asdfasdfasdfasdf

plaintext
{ "stuff": "here" }

NSData *encryptedData = [RNEncryptor encryptData:[@"{ \"stuff\": \"here\" }" dataUsingEncoding:NSUTF8StringEncoding]
                                            withSettings:kRNCryptorAES256Settings
                                                password:@"asdfasdfasdfasdf"
                                                   error:&error];

Using password and plaintext in the RNCryptor-objc encryption library I get:
cipher hex
03 01 59 fe 9e 5f f2 c2 05 58 ab 85 29 c5 a5 6f ad 27 5e e0 e8 a1 af f2 1f e4 e9 61 8b 25 44 1b ba ee e4 71 ef 95 e9 16 3b 59 53 a2 74 d9 23 00 57 1f a6 4f b9 ff 86 8d e6 ae 76 5a 4a 15 eb b8 d0 b4 bb 54 50 d0 76 3d 45 1c b5 c3 41 1f 1d 09 b8 97 6a ba 91 44 2e 1f f4 54 42 44 ce 59 b0 cc 0b 14 64 30

Break up cipher hex into parts below according to this format (https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md):
——————
version (1 byte)
03

options (1 byte)
01

encryption salt (8 bytes)
59 fe 9e 5f f2 c2 05 58

HMAC salt (8 bytes)
ab 85 29 c5 a5 6f ad 27

IV (16 bytes)
5e e0 e8 a1 af f2 1f e4 e9 61 8b 25 44 1b ba ee

ciphertext (x bytes)
e4 71 ef 95 e9 16 3b 59 53 a2 74 d9 23 00 57 1f a6 4f b9 ff 86 8d e6 ae 76 5a 4a 15 eb b8 d0 b4 bb 54

HMAC (32 bytes)
50 d0 76 3d 45 1c b5 c3 41 1f 1d 09 b8 97 6a ba 91 44 2e 1f f4 54 42 44 ce 59 b0 cc 0b 14 64 30

—————————

Using PBKDF2 function with 32 byte length, 10k iterations, SHA-1, and encryption salt (above), generate an encryption key (http://anandam.name/pbkdf2/):

encryption key
d57972b596a34a18e201d2f6a301424dcf269ccc757e07f91765935af491aa68

Then, decrypt to plaintext using ciphertext, IV, and encryption key using third party AES decryption function (http://extranet.cryptomathic.com/aescalc/index):
Decrypted plaintext in hex
AD409D9EFE09B360B2B905A82C41CE67BD7D106095742BFF055891F8CE1D524EAB6EDC147F565796ED7AAF6F4E8A024A

Convert from hex to ASCII:
Decrypted plaintext in ASCII
@ žþ ³²¹¨,AÎg½}•t+ÿX‘øÎRN«nÜ VW–íz¯oNŠJ


Obviously, I'm missing something here, but I'm not sure what it is. Am I missing padding on the cipher hex and/or HMAC and/or ciphertext? Am I not generating the encryption key correctly?

Thanks for any help you can provide,
Steve Y

RNCryptor: encrypt in python and decrypt in Objc

Hi,

I use rncryptor for encryption in python

rncryptor.encrypt(data, password)

and decrypt it in Objc:

[RNDecryptor decryptData:encryptedData
                                                    withPassword:aPassword
                                                           error:&error];

but error return Unknown header

I have checked password both side, and try for decrypt with python and it's works.

What is the corresponding openssl-algorithm for kRNCryptorAES256Settings?

I tried successfully your example code for working with streams. Using this library i can encrypt and decrypt files with the setting kRNCryptorAES256Settings.

But what setting is necessary to decrypt files, that were encrypted for instance with the "aes-256-cbc"-algorithm?

When i encrypt a file in the terminal with

openssl enc -aes-256-cbc -in m1010.jpg -out m1010.data

and decrypt this using RNDecryptor, the output is totally different and wrong.

Is there a list of corresponding settings available according to this library and those that are available in openssl? Thank you very much in advance

RNCryptor error decrypting between IOS and PHP

0

I use the RNCrytpor in my IOS app to encrypt and when I try too decrypt in server side with PHP, sometimes that work and sometime not, I don't know why, I have no error information in PHP side.

This is my simple IOS code to encrypt (I try to encrypt the current Timestamp only for my test)

NSString *password = @"myPassword";
//ENCRYPT TEST

NSDate *date = [NSDate date];
NSTimeInterval ti = [date timeIntervalSince1970];
NSString *strTmSmp = [NSString stringWithFormat:@"%.0f",ti];


NSString *strKey = [NSString stringWithFormat:@"hello_%@",strTmSmp];

NSData *data = [strKey dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
withSettings:kRNCryptorAES256Settings
  password:password
     error:&error];

NSString *keyValue = [encryptedData base64EncodedStringWithOptions:0];

NSDictionary *params = @{  @"key":  keyValue };

I use AfNetworking to POST my request

This is my simple PHP code to decrypt

$password = "myPassword";
$base64Encrypted = $_POST['key'];
$cryptor = new \RNCryptor\RNCryptor\Decryptor;
$plainText = @cryptor->decrypt($base64Encrypted,$password);
echo $plainText;

if someone can help me

Use of banned api in library

I have run the penetrating security test on the iOS app found issue with RNEncryptor library.
pen test error : The binary may contain the following insecure API(s).

Following are the classes which used insecure api methods (memcpy)-

  • RNCryptor.m (Line number 242, 275, 279, 282)

Could you provide a solution for this?
Please suggest if you have any alternative for it.

Security

We are using RNCryptor-objc library in our project for the purpose of encryption/decryption. While running static analyser tool for maintaining best security practices in our project, we have found one critical issue reported by the tool. Below is the issue:

Issue: "CBC mode is vulnerable to padding oracle attacks. CTR mode is the superior choice because it does not have these weaknesses."

As per the Description of RNCryptor-objc, the library used CBC mode.

So, I want to ask, is there any CTR mode version available for us to use. And if not, is there any possibility that you guys add it here in the library.

Also, there is a link placed in the library which says, "Mode changes for RNCryptor" but the link is not working.

Please let us know if you can help here and add the required mode which will be safer to use. Thanks!

Memory spike problem and the fix

When encrypting/decrypting large files, in our case, the memory usage spikes to 1.5G and app quickly crashes. We found the problem to be caused by RNCryptorEngine:addData:error creating 48K NSData objects that are not released fast enough. The fix is pretty simple: to add @autoreleaseblock to the two functions that use RNCryptorEngine:addData:error:

RNEncryptor:

- (void)addData:(NSData *)data
{
    if (self.isFinished) {
        return;
    }
    
    dispatch_async(self.queue, ^{
        @autoreleasepool { // this fixes the memory issue
            if (!self.haveWrittenHeader) {
                NSData *header = [self header];
                [self.outData setData:header];
                if (self.hasHMAC) {
                    CCHmacUpdate(&self->_HMACContext, [header bytes], [header length]);
                }
                self.haveWrittenHeader = YES;
            }
            
            NSError *error = nil;
            NSData *encryptedData = [self.engine addData:data error:&error];
            if (!encryptedData) {
                [self cleanupAndNotifyWithError:error];
            }
            if (self.hasHMAC) {
                CCHmacUpdate(&self->_HMACContext, encryptedData.bytes, encryptedData.length);
            }
            
            [self.outData appendData:encryptedData];
            
            dispatch_sync(self.responseQueue, ^{
                self.handler(self, self.outData);
            });
            [self.outData setLength:0];
        }
    });
}

RNDecryptor:

- (void)decryptData:(NSData *)data
{
    dispatch_async(self.queue, ^{
        @autoreleasepool { // this fixes the memory issue
            if (self.hasHMAC) {
                CCHmacUpdate(&self->_HMACContext, data.bytes, data.length);
            }
            
            NSError *error = nil;
            NSData *decryptedData = [self.engine addData:data error:&error];
            
            if (!decryptedData) {
                [self cleanupAndNotifyWithError:error];
                return;
            }
            
            [self.outData appendData:decryptedData];
            
            dispatch_sync(self.responseQueue, ^{
                self.handler(self, self.outData);
            });
            [self.outData setLength:0];
        }
    });
}

ios11 beta error

In the ios11 beta version, will report the following error: Conflicting types for 'SecRandomCopyBytes'
How can i solve it?

Error compiling for arm64

The compiler tells me "Symbols not found for architecture arm64"

"OBJC_CLASS$_RNDecryptor", referenced from:
objc-class-ref
"OBJC_CLASS$_RNEncryptor", referenced from:
objc-class-ref
"_kRNCryptorAES256Settings", referenced from:

Block implicitly retains 'self'

I am getting the above warning message in 6 places in the RNCryptor library. Full message is:

Pods/RNCryptor-objc/RNCryptor/RNDecryptor.m:169:21:
Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior

Also found in:
RNDecryptor.m:312:20
RNEncryptor.m:202:23
RNEncryptor.m:213:21
RNEncryptor.m:236:21
RNEncryptor.m:238:20

Everything else with the library seems to be working great! (I'm just trying to get rid of all warnings in my project, whether from my code or not.)

RNCryptor compatibility iOS 13

Hello there,

Is there anyone who managed to use RNCryptor on an iOS 13 device ? if so what's the compatible version ?

Have you forgot to release 3.0.5

While writing at Podfile as pod 'RNCryptor-objc', '3.0.5', it gives error as below:

[!] Unable to satisfy the following requirements:

- `RNCryptor-objc (= 3.0.5)` required by `Podfile`

None of your spec sources contain a spec satisfying the dependency: `RNCryptor-objc (= 3.0.5)`.

You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.

If writing without version as pod 'RNCryptor-objc' , it installs 3.0.2

Fortify security issue RNCryptor.m

Hi,

We are getting fortify security issue in function + (NSData *)randomDataOfLength:(size_t)length on below line
if (&SecRandomCopyBytes != NULL) {

Description :

This expression will always be non-null because it references a function pointer rather than the return value of the function.

Example 1: The following conditional will never fire. The predicate getChunk == NULL will always be false because getChunk is the name of a function defined in the program.

if (getChunk == NULL)
return ERR;

Thanks,
Usman

Can I user like this

Can I use like this, I just need simple use and less params? But It is not work correct for me. The 'base64Encrypt' is not right.

const RNCryptorSettings kRNCryptorAES128Settings = {
    .algorithm = kCCAlgorithmAES128,
    .blockSize = kCCBlockSizeAES128,
    .IVSize = kCCBlockSizeAES128,
    .options = kCCOptionPKCS7Padding
};

    NSData *data = [@"Data" dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error;
    NSData *encryptedData = [RNEncryptor encryptData:data
                                        withSettings:kRNCryptorAES128Settings
                                       encryptionKey:[@"15hcxttc3gas63st" dataUsingEncoding:NSUTF8StringEncoding]
                                             HMACKey:NULL
                                                  IV:[@"1234567890123456" dataUsingEncoding:NSUTF8StringEncoding]
                                               error:&error];
    
    NSString *base64Encrypt = [encryptedData base64EncodedStringWithOptions:0];

Synchronous methods hang on invalid key

Hey @rnapier,

I'm trying to refresh an old project by different developers who employed this library. However, it always seems to hang in the synchronousResultForCryptor:data:error: method. The semaphore there never seems to get signaled because the handler never seems to get called at all (i.e. https://github.com/RNCryptor/RNCryptor-objc/blob/master/RNCryptor/RNCryptor.m#L99-L122).

Am I missing some sort of dependency or configuration? I tried both with the old version originally in the project as well as the latest version here. I've spent several hours trying to figure this out and am really hoping you might have some ideas.

(For integration, I've tried the original grab-the-source-and-stick-it-in as well as Carthage. I noticed the Security framework is listed in the pod spec but assumed that would be automatically imported where a project generally needs it.)

Thanks in advance for your time in considering my little problem. 😄

P.S. I think I met you at a CocoaConf perhaps four or five years ago when you gave a talk on CoreText. I'm a native of Raleigh myself. 👍

Carthage

How can this be used with Carthage for an Objective-C project?

Decryption during download

Hello Rob,
Thank you very much for your effort in creating this brilliant library and spending time on maintaining it.
Could you please clarify the below question?
I have a bunch of audio files which are encrypted and stored in the server. The key is bundled with the client application.
Is it possible to use RNCryptor to decrypt the files during download, so that I can start playback before the file is completely downloaded?
I have gone through this discussion and as I understand, it is not supported, as of now.

Please share your thoughts on this.

Code Correctness

Hi
In the file RNEncryptor.m we have a security issue for code correctness.The snippet where issue is the method:
(NSData *)randomDataOfLength:(size_t)length
{
NSMutableData *data = [NSMutableData dataWithLength:length];

int result;
if (&SecRandomCopyBytes != NULL) {
result = SecRandomCopyBytes(NULL, length, data.mutableBytes);
}
Description: The issue is raised for &SecRandomCopyBytes i.e Because it is missing trailing parentheses, the expression on line 386 in RNCryptor.m refers to the value of a function pointer rather than the return value of the function.
Please suggest if the conecern is valid or not.

Decrypting File Encrypted with OpenSSL

Hi Rob.

Enjoying your encryption framework. But with the latest release it appears you have removed the RNOpenSSL encrypt and decrypt files.

I was unable to decrypt a file encrypted via terminal with OpenSSL. I tried the Basic Objective-C Usage in your documentation.

Is it still possible to use openssl with the latest RNCryptor version?

/Philip Borges

The error "HMAC Mismatch" appears when I decrypt audio, sometimes it happens, not each time.

Hi,
I got a problem when I decrypted my encrypted audio file, after called '[decryptor isFinished]', the problem would appear. The error is "HMAC Mismatch", but I have no idea to solve it.

`- (void)encryptionDidFinish {
if (self.encryptor.error) {
//---> code often comes here!!! I can't get correct audio file. <---\
self.encryptedData = nil;
self.encryptor = nil;
}
else {
// self.encryptedData is complete. Use it as you like
[self writeEncryptedData];
if ([self.delegate respondsToSelector:@selector(onEncryptionDidFinish)]) {
[self.delegate onEncryptionDidFinish];
}
self.encryptedData = nil;
self.encryptor = nil;
}

}`

Open encrypted file without decrypted local copy

Hi. @rnapier thank you for a job. I have a question. In my application I use UIWebVIew to view files (except images). UIWebVIew required data or link to the file. Data - not suitable for files can be quite large - so I can use NSOutputStream for decrypt - but in this case will need to create a local copy of the decrypted file (in a temp dir). Is there an alternative way, do not make copies of decrypted files?

'RNCryptor.h' file not found

I try to use RNCryptor in my app like so:

In my project:
Cartfile: github "RNCryptor/RNCryptor-objc"
carthage update RNCryptor-objc
Add framework to "General / Linked frameworks and libraries"

In a class file:
#import <RNCryptor/RNCryptor.h>

When trying to build:
While building module 'RNCryptor' imported from /Users/udo/Documents/Xcode-Projects/aktiv/Tresor/Shared/TSCryptoKeys.m:11: In file included from <module-includes>:1: In file included from /Users/udo/Documents/Xcode-Projects/aktiv/Tresor/Carthage/Build/iOS/RNCryptor.framework/Headers/RNCryptor iOS.h:22: /Users/udo/Documents/Xcode-Projects/aktiv/Tresor/Carthage/Build/iOS/RNCryptor.framework/PrivateHeaders/RNCryptorEngine.h:29:9: fatal error: 'RNCryptor.h' file not found #import "RNCryptor.h" ^ 1 error generated.

What am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.