A Dart library providing utilities for encryption, HTTP operations, and contact management for Infgety database feature. This library helps you implement database configurations that Infgety users can add to their applications.
- AES Encryption/Decryption: Secure data encryption and decryption using AES CBC mode
- HTTP Utilities: Simplified HTTP GET and POST operations
- Contact Management: Data structures for handling contact information and queries
- Utility Functions: Helper functions for data validation and conversion
- Custom Exceptions: Specialized exception handling for Infgety operations
Add this package to your pubspec.yaml
:
dependencies:
infgety_database:
git:
url: https://github.com/PSHTeam/infgety_database.git
Then run:
dart pub get
Import the package in your Dart code:
import 'package:infgety_database/infgety_database.dart';
The AES
class provides AES encryption and decryption capabilities using CBC mode.
AES({
required String keyHex, // Hexadecimal key string
required String ivHex, // Hexadecimal initialization vector
String? encoding, // Optional encoding: 'base64', 'base16', or 'utf8'
})
String encrypt(String plainText)
- Encrypts plain text and returns encrypted stringString decrypt(String cipherText)
- Decrypts cipher text and returns plain text
final aes = AES(
keyHex: 'your_32_character_hex_key_here',
ivHex: 'your_32_character_hex_iv_here',
encoding: 'base64',
);
String encrypted = aes.encrypt('Hello, World!');
String decrypted = aes.decrypt(encrypted);
print(decrypted); // Output: Hello, World!
A data model representing a contact with name and quantity information.
ContactName({
required String name, // Contact name
required int quantity, // Associated quantity
})
final contact = ContactName(
name: 'John Doe',
quantity: 5,
);
A query model for fetching contact information based on phone number details.
FetchContactsQuery({
required String nationalNumber, // National phone number
required String countryCode, // Country code
required String regionCode, // Region code
})
FetchContactsQuery.fromArgs(List<String> args)
Creates a FetchContactsQuery
from a list of string arguments. Requires at least 3 arguments.
final query = FetchContactsQuery(
nationalNumber: '1234567890',
countryCode: 'US',
regionCode: 'CA',
);
// Or from arguments
final queryFromArgs = FetchContactsQuery.fromArgs([
'1234567890',
'US',
'CA'
]);
A custom exception class for handling Infgety-specific errors.
InfgetyException(String message)
try {
// Some operation that might fail
throw InfgetyException('Operation failed');
} catch (e) {
if (e is InfgetyException) {
print('Infgety error: ${e.message}');
}
}
Future<Response> post(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding})
Future<Response> get(Uri url, {Map<String, String>? headers})
final response = await post(
Uri.parse('https://api.example.com/data'),
headers: {'Content-Type': 'application/json'},
body: '{"key": "value"}',
);
bool isNull(Object? object)
- Checks if an object is nullString uint8ListToHex(Uint8List input)
- Converts Uint8List to hexadecimal string
bool nullCheck = isNull(someVariable);
Uint8List data = Uint8List.fromList([255, 16, 32]);
String hexString = uint8ListToHex(data); // Returns: "ff1020"
import 'package:infgety_database/infgety_database.dart';
void main() async {
// AES Encryption
final aes = AES(
keyHex: '0123456789abcdef0123456789abcdef',
ivHex: 'fedcba9876543210fedcba9876543210',
encoding: 'base64',
);
String encrypted = aes.encrypt('Sensitive data');
print('Encrypted: $encrypted');
String decrypted = aes.decrypt(encrypted);
print('Decrypted: $decrypted');
// Contact handling
final contact = ContactName(name: 'Alice Smith', quantity: 10);
// Query creation
final query = FetchContactsQuery(
nationalNumber: '5551234567',
countryCode: 'US',
regionCode: 'NY',
);
// HTTP request
try {
final response = await get(Uri.parse('https://api.example.com/contacts'));
print('Response status: ${response.statusCode}');
} catch (e) {
print('HTTP error: $e');
}
// Utility functions
print('Is null: ${isNull(null)}'); // true
print('Is null: ${isNull('data')}'); // false
}