Fix/Update #1
							
								
								
									
										44
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								README.md
									
									
									
									
									
								
							| @ -47,8 +47,6 @@ To digest a message, you can use the following function: | |||||||
| Uint8List hash = await HashAlgorithm.sha256.digest(message); | Uint8List hash = await HashAlgorithm.sha256.digest(message); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Note that you can find a `toBytes()` method in the example app, to convert a `String` to a `Uint8List`. |  | ||||||
| 
 |  | ||||||
| > In NativeCrypto, you can use the following hash functions: SHA-256, SHA-384, SHA-512 | > In NativeCrypto, you can use the following hash functions: SHA-256, SHA-384, SHA-512 | ||||||
| 
 | 
 | ||||||
| #### Keys | #### Keys | ||||||
| @ -70,7 +68,11 @@ You can derive a `SecretKey` using **PBKDF2**. | |||||||
| First, you need to initialize a `Pbkdf2` object. | First, you need to initialize a `Pbkdf2` object. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| Pbkdf2 pbkdf2 = Pbkdf2(32, 1000, algorithm: HashAlgorithm.sha512); | Pbkdf2 pbkdf2 = Pbkdf2( | ||||||
|  |     keyBytesCount: 32, | ||||||
|  |     iterations: 1000, | ||||||
|  |     algorithm: HashAlgorithm.sha512, | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Then, you can derive a `SecretKey` from a password and salt. | Then, you can derive a `SecretKey` from a password and salt. | ||||||
| @ -88,22 +90,40 @@ And now, you can use the `SecretKey` to encrypt/decrypt a message. | |||||||
| First, you need to initialize a `Cipher` object. | First, you need to initialize a `Cipher` object. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| AES cipher = AES(secretKey, AESMode.gcm); | AES cipher = AES(secretKey); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Then, you can encrypt/decrypt your message. | Then, you can encrypt your message. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| CipherText encrypted = await cipher.encrypt(message); | CipherTextWrapper wrapper = await cipher.encrypt(message); | ||||||
| Uint8List decrypted = await cipher.decrypt(encrypted); | 
 | ||||||
|  | CipherText cipherText = wrapper.unwrap<CipherText>(); | ||||||
|  | // same as | ||||||
|  | CipherText cipherText = wrapper.single; | ||||||
|  | 
 | ||||||
|  | // or | ||||||
|  | 
 | ||||||
|  | List<CipherText> cipherTexts = wrapper.unwrap<List<CipherText>>(); | ||||||
|  | // same as | ||||||
|  | List<CipherText> cipherTexts = wrapper.list; | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| After an encryption, you can use the `CipherText` object to access underlying data. | After an encryption you obtain a `CipherTextWrapper` which contains `CipherText` or `List<CipherText>` depending on the message size. It's up to you to know how to unwrap the `CipherTextWrapper` depending the chunk size you configured. | ||||||
|  | 
 | ||||||
|  | Uppon receiving encrypted message, you can decrypt it. | ||||||
|  | You have to reconstruct the wrapper before decrypting. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| Uint8List iv = encrypted.iv; | CipherTextWrapper wrapper = CipherTextWrapper.fromBytes( | ||||||
| Uint8List data = encrypted.data; |     data, | ||||||
| Uint8List tag = encrypted.tag; |     ivLength: AESMode.gcm.ivLength, | ||||||
|  |     tagLength: AESMode.gcm.tagLength, | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Note that data and tag are costly to access, so you should only use them if you need to ! | Then, you can decrypt your message. | ||||||
|  | 
 | ||||||
|  | ```dart | ||||||
|  | Uint8List message = await cipher.decrypt(wrapper); | ||||||
|  | ``` | ||||||
| @ -47,8 +47,6 @@ To digest a message, you can use the following function: | |||||||
| Uint8List hash = await HashAlgorithm.sha256.digest(message); | Uint8List hash = await HashAlgorithm.sha256.digest(message); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Note that you can find a `toBytes()` method in the example app, to convert a `String` to a `Uint8List`. |  | ||||||
| 
 |  | ||||||
| > In NativeCrypto, you can use the following hash functions: SHA-256, SHA-384, SHA-512 | > In NativeCrypto, you can use the following hash functions: SHA-256, SHA-384, SHA-512 | ||||||
| 
 | 
 | ||||||
| #### Keys | #### Keys | ||||||
| @ -70,7 +68,11 @@ You can derive a `SecretKey` using **PBKDF2**. | |||||||
| First, you need to initialize a `Pbkdf2` object. | First, you need to initialize a `Pbkdf2` object. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| Pbkdf2 pbkdf2 = Pbkdf2(32, 1000, algorithm: HashAlgorithm.sha512); | Pbkdf2 pbkdf2 = Pbkdf2( | ||||||
|  |     keyBytesCount: 32, | ||||||
|  |     iterations: 1000, | ||||||
|  |     algorithm: HashAlgorithm.sha512, | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Then, you can derive a `SecretKey` from a password and salt. | Then, you can derive a `SecretKey` from a password and salt. | ||||||
| @ -88,22 +90,40 @@ And now, you can use the `SecretKey` to encrypt/decrypt a message. | |||||||
| First, you need to initialize a `Cipher` object. | First, you need to initialize a `Cipher` object. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| AES cipher = AES(secretKey, AESMode.gcm); | AES cipher = AES(secretKey); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Then, you can encrypt/decrypt your message. | Then, you can encrypt your message. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| CipherText encrypted = await cipher.encrypt(message); | CipherTextWrapper wrapper = await cipher.encrypt(message); | ||||||
| Uint8List decrypted = await cipher.decrypt(encrypted); | 
 | ||||||
|  | CipherText cipherText = wrapper.unwrap<CipherText>(); | ||||||
|  | // same as | ||||||
|  | CipherText cipherText = wrapper.single; | ||||||
|  | 
 | ||||||
|  | // or | ||||||
|  | 
 | ||||||
|  | List<CipherText> cipherTexts = wrapper.unwrap<List<CipherText>>(); | ||||||
|  | // same as | ||||||
|  | List<CipherText> cipherTexts = wrapper.list; | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| After an encryption, you can use the `CipherText` object to access underlying data. | After an encryption you obtain a `CipherTextWrapper` which contains `CipherText` or `List<CipherText>` depending on the message size. It's up to you to know how to unwrap the `CipherTextWrapper` depending the chunk size you configured. | ||||||
|  | 
 | ||||||
|  | Uppon receiving encrypted message, you can decrypt it. | ||||||
|  | You have to reconstruct the wrapper before decrypting. | ||||||
| 
 | 
 | ||||||
| ```dart | ```dart | ||||||
| Uint8List iv = encrypted.iv; | CipherTextWrapper wrapper = CipherTextWrapper.fromBytes( | ||||||
| Uint8List data = encrypted.data; |     data, | ||||||
| Uint8List tag = encrypted.tag; |     ivLength: AESMode.gcm.ivLength, | ||||||
|  |     tagLength: AESMode.gcm.tagLength, | ||||||
|  | ); | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Note that data and tag are costly to access, so you should only use them if you need to ! | Then, you can decrypt your message. | ||||||
|  | 
 | ||||||
|  | ```dart | ||||||
|  | Uint8List message = await cipher.decrypt(wrapper); | ||||||
|  | ``` | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user