Skip to content

Commit d3175a0

Browse files
committed
Fix key size
1 parent 6201c8b commit d3175a0

File tree

5 files changed

+100
-49
lines changed

5 files changed

+100
-49
lines changed

.prettierrc.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
printWidth: 100,
3+
tabWidth: 4,
4+
useTabs: false,
5+
semi: false,
6+
singleQuote: true,
7+
trailingComma: 'es5',
8+
bracketSpacing: true,
9+
jsxBracketSameLine: false,
10+
arrowParens: 'avoid',
11+
proseWrap: 'never',
12+
overrides: [
13+
{
14+
files: '*.vue',
15+
options: {
16+
printWidth: 100,
17+
},
18+
parser: 'vue',
19+
},
20+
],
21+
}

README.md

+59-46
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,34 @@
33
AES encryption/decryption for react-native
44

55
## Installation
6+
67
```sh
78
npm install --save react-native-aes-crypto
89
```
10+
911
or
12+
1013
```sh
1114
yarn add react-native-aes-crypto
1215
```
16+
1317
### Installation (iOS)
14-
* See [Linking Libraries](http://facebook.github.io/react-native/docs/linking-libraries-ios.html)
15-
OR
16-
* Drag RCTAes.xcodeproj to your project on Xcode.
17-
* Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTAes.a from the Products folder inside the RCTAes.xcodeproj.
18+
19+
- See [Linking Libraries](http://facebook.github.io/react-native/docs/linking-libraries-ios.html) OR
20+
- Drag RCTAes.xcodeproj to your project on Xcode.
21+
- Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTAes.a from the Products folder inside the RCTAes.xcodeproj.
1822

1923
### Installation (Android)
24+
2025
#### Untested!
26+
2127
```gradle
2228
...
2329
include ':react-native-aes-crypto'
2430
project(':react-native-aes-crypto').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-aes-crypto/android')
2531
```
2632

27-
* In `android/app/build.gradle`
33+
- In `android/app/build.gradle`
2834

2935
```gradle
3036
...
@@ -34,7 +40,7 @@ dependencies {
3440
}
3541
```
3642

37-
* register module (in MainApplication.java)
43+
- register module (in MainApplication.java)
3844

3945
```java
4046
......
@@ -55,40 +61,47 @@ protected List<ReactPackage> getPackages() {
5561
### Example
5662

5763
```js
58-
import { NativeModules, Platform } from 'react-native';
59-
var Aes = NativeModules.Aes;
64+
import { NativeModules, Platform } from 'react-native'
65+
var Aes = NativeModules.Aes
6066

61-
62-
const generateKey = (password, salt, cost, length) => Aes.pbkdf2(password, salt, cost, length);
67+
const generateKey = (password, salt, cost, length) => Aes.pbkdf2(password, salt, cost, length)
6368

6469
const encrypt = (text, keyBase64) => {
65-
var ivBase64 = "base64 random 16 bytes string";
66-
return Aes.encrypt(text, keyBase64, ivBase64).then(cipher => ({ cipher, iv: ivBase64 }));
67-
};
70+
return Aes.randomKey(32).then(iv => {
71+
return Aes.encrypt(text, keyBase64, iv).then(cipher => ({
72+
cipher,
73+
iv,
74+
}))
75+
})
76+
}
6877

69-
const decrypt = (encryptedData, key) => Aes.decrypt(encryptedData.cipher, key, encryptedData.iv);
78+
const decrypt = (encryptedData, key) => Aes.decrypt(encryptedData.cipher, key, encryptedData.iv)
7079

7180
try {
72-
generateKey("Arnold", "salt", 5000, 512).then(key => {
73-
console.log('Key:', key);
74-
encrypt("These violent delights have violent ends", key).then(({cipher, iv}) => {
75-
console.log("Encrypted:", cipher);
76-
77-
decrypt({ cipher, iv }, key).then(text => {
78-
console.log("Decrypted:", text);
79-
}).catch(error => {
80-
console.log(error);
81-
});
82-
83-
Aes.hmac256(cipher, key).then(hash => {
84-
console.log("HMAC", hash);
85-
});
86-
}).catch(error => {
87-
console.log(error);
88-
});
89-
});
81+
generateKey('Arnold', 'salt', 5000, 512).then(key => {
82+
console.log('Key:', key)
83+
encrypt('These violent delights have violent ends', key)
84+
.then(({ cipher, iv }) => {
85+
console.log('Encrypted:', cipher)
86+
87+
decrypt({ cipher, iv }, key)
88+
.then(text => {
89+
console.log('Decrypted:', text)
90+
})
91+
.catch(error => {
92+
console.log(error)
93+
})
94+
95+
Aes.hmac256(cipher, key).then(hash => {
96+
console.log('HMAC', hash)
97+
})
98+
})
99+
.catch(error => {
100+
console.log(error)
101+
})
102+
})
90103
} catch (e) {
91-
console.error(e);
104+
console.error(e)
92105
}
93106
```
94107

@@ -97,23 +110,23 @@ try {
97110
```js
98111
async function asyncDecrypt(cipher, key, iv) {
99112
try {
100-
var text = await decrypt({ cipher, iv }, key);
101-
console.log(text);
102-
return text;
113+
var text = await decrypt({ cipher, iv }, key)
114+
console.log(text)
115+
return text
103116
} catch (e) {
104-
console.error(e);
117+
console.error(e)
105118
}
106119
}
107120
```
108121

109122
### methods
110123

111-
- `encrypt(text, key, iv)`
112-
- `decrypt(base64, key, iv)`
113-
- `pbkdf2(text, salt, cost, length)`
114-
- `hmac256(cipher, key)`
115-
- `sha1(text)`
116-
- `sha256(text)`
117-
- `sha512(text)`
118-
- `randomUuid()`
119-
- `randomKey(length)`
124+
- `encrypt(text, key, iv)`
125+
- `decrypt(base64, key, iv)`
126+
- `pbkdf2(text, salt, cost, length)`
127+
- `hmac256(cipher, key)`
128+
- `sha1(text)`
129+
- `sha256(text)`
130+
- `sha512(text)`
131+
- `randomUuid()`
132+
- `randomKey(length)`

ios/RCTAes.xcodeproj/project.pbxproj

+18-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
32D980D51BE9F11C00FA27E5 /* Project object */ = {
106106
isa = PBXProject;
107107
attributes = {
108-
LastUpgradeCheck = 0820;
108+
LastUpgradeCheck = 1010;
109109
ORGANIZATIONNAME = tectiv3;
110110
TargetAttributes = {
111111
32D980DC1BE9F11C00FA27E5 = {
@@ -151,20 +151,29 @@
151151
CLANG_CXX_LIBRARY = "libc++";
152152
CLANG_ENABLE_MODULES = YES;
153153
CLANG_ENABLE_OBJC_ARC = YES;
154+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
154155
CLANG_WARN_BOOL_CONVERSION = YES;
156+
CLANG_WARN_COMMA = YES;
155157
CLANG_WARN_CONSTANT_CONVERSION = YES;
158+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
156159
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
157160
CLANG_WARN_EMPTY_BODY = YES;
158161
CLANG_WARN_ENUM_CONVERSION = YES;
159162
CLANG_WARN_INFINITE_RECURSION = YES;
160163
CLANG_WARN_INT_CONVERSION = YES;
164+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
165+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
166+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
161167
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
168+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
169+
CLANG_WARN_STRICT_PROTOTYPES = YES;
162170
CLANG_WARN_SUSPICIOUS_MOVE = YES;
163171
CLANG_WARN_UNREACHABLE_CODE = YES;
164172
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
165173
COPY_PHASE_STRIP = NO;
166174
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
167175
ENABLE_STRICT_OBJC_MSGSEND = YES;
176+
ENABLE_TESTABILITY = YES;
168177
GCC_C_LANGUAGE_STANDARD = gnu99;
169178
GCC_DYNAMIC_NO_PIC = NO;
170179
GCC_NO_COMMON_BLOCKS = YES;
@@ -195,14 +204,22 @@
195204
CLANG_CXX_LIBRARY = "libc++";
196205
CLANG_ENABLE_MODULES = YES;
197206
CLANG_ENABLE_OBJC_ARC = YES;
207+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
198208
CLANG_WARN_BOOL_CONVERSION = YES;
209+
CLANG_WARN_COMMA = YES;
199210
CLANG_WARN_CONSTANT_CONVERSION = YES;
211+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
200212
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
201213
CLANG_WARN_EMPTY_BODY = YES;
202214
CLANG_WARN_ENUM_CONVERSION = YES;
203215
CLANG_WARN_INFINITE_RECURSION = YES;
204216
CLANG_WARN_INT_CONVERSION = YES;
217+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
218+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
219+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
205220
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
221+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
222+
CLANG_WARN_STRICT_PROTOTYPES = YES;
206223
CLANG_WARN_SUSPICIOUS_MOVE = YES;
207224
CLANG_WARN_UNREACHABLE_CODE = YES;
208225
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

ios/RCTAes/lib/AesCrypt.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ + (NSData *) AES128CBC: (NSString *)operation data: (NSData *)data key: (NSStrin
7474
[operation isEqualToString:@"encrypt"] ? kCCEncrypt : kCCDecrypt,
7575
kCCAlgorithmAES128,
7676
kCCOptionPKCS7Padding,
77-
keyData.bytes, kCCKeySizeAES256,
77+
keyData.bytes, kCCKeySizeAES128,
7878
ivData.bytes,
7979
data.bytes, data.length,
8080
buffer.mutableBytes, buffer.length,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-aes-crypto",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "AES crypto native module for react-native",
55
"main": "index.js",
66
"author": "tectiv3",

0 commit comments

Comments
 (0)