Expand description
§Cryptolens Rust Client
This crate provides helper function for managing and verifying license keys using cryptolens. It handles key activations, validations, and provides utilities for working with RSA keys for digital signatures.
§Examples
§Basic usage:
use cryptolens_yc::{key_activate, KeyActivateArguments};
// this is the example in original documentation
let public_key = "<RSAKeyValue><Modulus>khbyu3/vAEBHi339fTuo2nUaQgSTBj0jvpt5xnLTTF35FLkGI+5Z3wiKfnvQiCLf+5s4r8JB/Uic/i6/iNjPMILlFeE0N6XZ+2pkgwRkfMOcx6eoewypTPUoPpzuAINJxJRpHym3V6ZJZ1UfYvzRcQBD/lBeAYrvhpCwukQMkGushKsOS6U+d+2C9ZNeP+U+uwuv/xu8YBCBAgGb8YdNojcGzM4SbCtwvJ0fuOfmCWZvUoiumfE4x7rAhp1pa9OEbUe0a5HL+1v7+JLBgkNZ7Z2biiHaM6za7GjHCXU8rojatEQER+MpgDuQV3ZPx8RKRdiJgPnz9ApBHFYDHLDzDw==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
let product_id = "3646";
let key = "MPDWY-PQAOW-FKSCH-SGAAU";
let token = "WyI0NjUiLCJBWTBGTlQwZm9WV0FyVnZzMEV1Mm9LOHJmRDZ1SjF0Vk52WTU0VzB2Il0=";
let license_key = key_activate(
token,
KeyActivateArguments {
ProductId: product_id.parse().unwrap(),
Key: key.to_string(),
MachineCode: "289jf2afs3".to_string(),
..Default::default()
},
).unwrap();
match license_key.has_valid_signature(public_key) {
Ok(valid) => assert_eq!(valid, true),
Err(e) => panic!("Error: {}", e),
}
§Offline Validation Example
// get the license key from above code ...
// save the license key to a file
let path = "cached_license_key";
save_license_key_to_file(&license_key, path)?;
// you can also load the license key from a file
let loaded_license_key = cryptolens_yc::load_license_key_from_file(path)?;
// validate the loaded license key
match loaded_license_key.has_valid_signature(public_key) {
Ok(valid) => assert_eq!(valid, true),
Err(e) => panic!("Error: {}", e),
}
Structs§
- Activate
Response - Represents the response from an activation request.
- Activation
Data - Represents data about an activation instance.
- Customer
- Customer information associated with a license key.
- Data
Object - A data object that can store custom information.
- KeyActivate
Arguments - Arguments used to activate a product key.
- License
Key - Represents a license key in cryptolens format.
Functions§
- key_
activate - Activates a license key using the cryptolens API.
- load_
license_ key_ from_ file - Loads a license key from a file.
- save_
license_ key_ to_ file - Encodes and saves a license key to a file.