सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
encrypt पैकेज फ्लटर एप्लिकेशन में दो-तरफा एन्क्रिप्शन के लिए उच्च स्तर के, आसान उपयोग वाले एपीआई प्रदान करता है, जो PointyCastle पर आधारित है। यह AES, RSA और DES जैसे विभिन्न एल्गोरिदम के समर्थन के साथ एन्क्रिप्शन और डिक्रिप्शन प्रक्रियाओं को सरल बनाता है। विकासकर्ताओं के लिए सुरक्षित डेटा हैंडलिंग की आवश्यकता के लिए डिज़ाइन किया गया है, जो संवेदनशील जानकारी के सुरक्षित स्टोरेज और ट्रांसमिशन को संभव बनाता है। पैकेज निम्न-स्तरीय एन्क्रिप्शन कठिनाइयों को अब्स्ट्रैक्ट करता है, जिससे गहन एन्क्रिप्शन विशेषज्ञता के बिना भी सुरक्षित कोडिंग उपलब्ध होती है।
उपयोग
सुरक्षित डेटा संग्रहण
उपयोगकर्ता प्रमाण हस्तांतरण करना
क्लाइंट और सर्वर के बीच सुरक्षित संचार
संवेदनशील ऐप डेटा की सुरक्षा
एंड-टू-एंड एन्क्रिप्शन का कार्यान्वयन
टोकन-आधारित प्रमाणीकरण
मुख्य विशेषताएँ
AES, RSA और DES के लिए समर्थन
सरल, स्पष्ट एपीआई
प्लेटफॉर्म के अनुकूलता
PointyCastle के साथ एकीकरण
निर्मित पैडिंग और मोड विकल्प
लचीला कुंजी और IV प्रबंधन
इनके लिए उपयुक्त
डेटा गोपनीयता की आवश्यकता वाले ऐप्स
क्रिप्टोग्राफी में नए विकासकर्ता
सुरक्षित स्थानीय भंडारण की आवश्यकता वाले प्रोजेक्ट
संवेदनशील उपयोगकर्ता जानकारी का प्रबंधन करने वाले एप्लिकेशन
सुरक्षा की आवश्यकता वाले बहु-प्लेटफॉर्म एप्लिकेशन
विचार योग्य बातें
सावधानीपूर्वक कुंजी प्रबंधन की आवश्यकता होती है
पासवर्ड हैशिंग के लिए उपयुक्त नहीं
PointyCastle की स्थिरता पर निर्भर करता है
उचित त्रुटि संभाल के साथ उपयोग किया जाना चाहिए
सुरक्षित की भंडारण समाधान के साथ सबसे अच्छा जोड़ा
स्रोत कोड में की को कठोर रूप से कोड करने से बचें
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
[!CAUTION]
I'm not being able to properly maintain this package, so it is being archived. Feel free to use some fork as an alternative.
encrypt
A set of high-level APIs over PointyCastle for two-way cryptography.
Looking for password hashing? Please, visit password.
Secure random
You can generate cryptographically secure random keys and IVs for you project.
$ secure-random --help
-l, --length The length of the bytes
(defaults to "32")
-b, --base Bytes represented as base 64 or base 16 (Hexdecimal)
(defaults to "64")
-h, --[no-]help Show this help message
Algorithms
Current status is:
AES with PKCS7 padding
RSA with PKCS1 and OAEP encoding
Salsa20
Signing
SHA256 with RSA
Usage
Symmetric
AES
import'package:encrypt/encrypt.dart';
voidmain() {
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final key = Key.fromUtf8('my 32 length key................');
final iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elitprint(encrypted.base64); // R4PxiU3h8YoIRqVowBXm36ZcCeNeZ4s1OvVBTfFlZRdmohQqOpPQqD1YecJeZMAop/hZ4OxqgC1WtwvX/hP9mw==
}
Modes of operation
Default mode is SIC AESMode.sic, you can override it using the mode named parameter:
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
Supported modes are:
CBC AESMode.cbc
CFB-64 AESMode.cfb64
CTR AESMode.ctr
ECB AESMode.ecb
OFB-64/GCTR AESMode.ofb64Gctr
OFB-64 AESMode.ofb64
SIC AESMode.sic
No/zero padding
To remove padding, pass null to the padding named parameter on the constructor:
final encrypter = Encrypter(AES(key, mode: AESMode.cbc, padding: null));
Salsa20
import'package:encrypt/encrypt.dart';
voidmain() {
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final key = Key.fromLength(32);
final iv = IV.fromLength(8);
final encrypter = Encrypter(Salsa20(key));
final encrypted = encrypter.encrypt(plainText, iv: iv);
final decrypted = encrypter.decrypt(encrypted, iv: iv);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elitprint(encrypted.base64); // CR+IAWBEx3sA/dLkkFM/orYr9KftrGa7lIFSAAmVPbKIOLDOzGwEi9ohstDBqDLIaXMEeulwXQ==
}
import'package:encrypt/encrypt.dart';
import'dart:convert';
voidmain() {
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final key = Key.fromUtf8('my32lengthsupersecretnooneknows1');
final b64key = Key.fromUtf8(base64Url.encode(key.bytes).substring(0,32));
// if you need to use the ttl feature, you'll need to use APIs in the algorithm itselffinal fernet = Fernet(b64key);
final encrypter = Encrypter(fernet);
final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt(encrypted);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elitprint(encrypted.base64); // random cipher textprint(fernet.extractTimestamp(encrypted.bytes)); // unix timestamp
}
Asymmetric
RSA
import'dart:io';
import'package:encrypt/encrypt.dart';
import'package:pointycastle/asymmetric/api.dart';
voidmain() {
final publicKey = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
final privKey = await parseKeyFromFile<RSAPrivateKey>('test/private.pem');
final plainText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
final encrypter = Encrypter(RSA(publicKey: publicKey, privateKey: privKey));
final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt(encrypted);
print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elitprint(encrypted.base64); // kO9EbgbrSwiq0EYz0aBdljHSC/rci2854Qa+nugbhKjidlezNplsEqOxR+pr1RtICZGAtv0YGevJBaRaHS17eHuj7GXo1CM3PR6pjGxrorcwR5Q7/bVEePESsimMbhHWF+AkDIX4v0CwKx9lgaTBgC8/yJKiLmQkyDCj64J3JSE=
}
Signature and verification
RSA
final publicKey = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
final privateKey = await parseKeyFromFile<RSAPrivateKey>('test/private.pem');
final signer = Signer(RSASigner(RSASignDigest.SHA256, publicKey: publicKey, privateKey: privateKey));
print(signer.sign('hello world').base64);
print(signer.verify64('hello world', 'jfMhNM2v6hauQr6w3ji0xNOxGInHbeIH3DHlpf2W3vmSMyAuwGHG0KLcunggG4XtZrZPAib7oHaKEAdkHaSIGXAtEqaAvocq138oJ7BEznA4KVYuMcW9c8bRy5E4tUpikTpoO+okHdHr5YLc9y908CAQBVsfhbt0W9NClvDWegs='));