Crates.io | spatial-hasher |
lib.rs | spatial-hasher |
version | 0.1.7 |
source | src |
created_at | 2024-09-24 08:29:57.403179 |
updated_at | 2024-09-24 13:30:38.825914 |
description | A Rust library for deterministic encryption and decryption using 3D spatial parameters with secure authenticated encryption. |
homepage | https://github.com/Wolfenheimm/spatial-hasher |
repository | https://github.com/Wolfenheimm/Spatial-Hasher |
max_upload_size | |
id | 1384902 |
size | 70,024 |
A Rust library for deterministic encryption and decryption using 3D spatial parameters with secure authenticated encryption.
spatial_hasher
provides a way to encrypt and decrypt data using a deterministic algorithm based on 3D spatial parameters. It utilizes a combination of a 3D point, a rotation axis, the number of iterations, and a strength parameter to derive a cryptographic key using SHA-256 hashing. This key is then used with the ChaCha20-Poly1305 authenticated encryption algorithm to ensure secure encryption and decryption.
serde
.Add spatial_hasher
to your Cargo.toml
dependencies:
[dependencies]
spatial_hasher = "0.1.0"
First, import the necessary structs:
use spatial_hasher::{Point3D, RotationAxis, Spha256};
Create a spatial_hasher instance by specifying the starting point, rotation axis, number of iterations, and strength:
let point = Point3D { x: 1.0, y: 2.0, z: 3.0 };
let rotation_axis = RotationAxis { x: 0.0, y: 1.0, z: 0.0 };
let iterations = 10;
let strength = 0.1;
let hasher = Spha256::new(point, rotation_axis, iterations, strength);
Encrypt data by passing a byte slice to the encrypt method:
let data = b"Secret Message";
let encrypted_data = hasher.encrypt(data);
Decrypt data by passing the encrypted byte slice to the decrypt method:
let decrypted_data = hasher.decrypt(&encrypted_data).expect("Decryption failed");
assert_eq!(data, &decrypted_data[..]);
Below is a complete example demonstrating how to use spatial_hasher:
use spatial_hasher::{Point3D, RotationAxis, Spha256};
fn main() {
// Define the starting point and rotation axis
let point = Point3D {
x: 1.0,
y: 2.0,
z: 3.0,
};
let rotation_axis = RotationAxis {
x: 0.0,
y: 1.0,
z: 0.0,
};
let iterations = 10;
let strength = 0.1;
// Create a new Spha256 instance
let hasher = Spha256::new(point, rotation_axis, iterations, strength);
// Original data to be encrypted
let original_data = b"Hello, World!";
println!("Original Data: {:?}", String::from_utf8_lossy(original_data));
// Encrypt the data
let encrypted = hasher.encrypt(original_data);
println!("Encrypted Data: {:?}", encrypted);
// Decrypt the data
let decrypted = hasher.decrypt(&encrypted).expect("Decryption failed");
println!("Decrypted Data: {:?}", String::from_utf8_lossy(&decrypted));
// Verify that the decrypted data matches the original data
assert_eq!(original_data, &decrypted[..], "Decryption failed");
}
Output:
Original Data: "Hello, World!"
Encrypted Data: [ ... ]
Decrypted Data: "Hello, World!"
Run the unit tests included with spatial_hasher using:
cargo test
spatial_hasher
relies on the following crates:
rand
for random number generation.chacha20poly1305
for the ChaCha20-Poly1305 cipher.serde
for serialization and deserialization.sha2
for SHA-256 hashing.spatial_hasher
now uses the ChaCha20-Poly1305 authenticated encryption algorithm, which provides strong security guarantees for both confidentiality and integrity. The encryption key is derived deterministically from the input parameters using SHA-256 hashing.
Point3D
, RotationAxis
, iterations
, and strength
) used to derive the key. Keep these parameters confidential and secure.While spatial_hasher
provides robust encryption, it's crucial to follow best practices in key management and security to maintain the confidentiality and integrity of your data.
The software Spatial Hasher is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or contributors be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Under no circumstances shall the authors or contributors be liable for any indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
The users of Spatial Hasher are solely responsible for compliance with all applicable laws and regulations, including but not limited to data encryption laws and export controls. The authors and contributors shall not be held responsible for any misuse of the software that may result in violation of any laws or regulations.
This software is not designed, intended, or authorized for use in any type of system or application where the failure of the software could create a situation where personal injury or death may occur (e.g., life-support systems, emergency services, nuclear facilities, or aircraft navigation or communication systems). The users agree that they will not use or redistribute the software for such purposes.
The authors and contributors have no obligation to provide maintenance, support, updates, enhancements, or modifications to the software. Any such support provided shall be at the sole discretion of the authors and contributors.
By using Spatial Hasher, you signify your acceptance of this disclaimer. If you do not agree to this disclaimer, you must not use the software.
spatial_hasher
should not be used for encrypting sensitive or confidential data. The encryption provided is suitable for obfuscation or simple data hiding in contexts where strong security is not required. Use at your own risk.
For applications requiring robust, secure encryption, please use established cryptographic libraries such as the RustCrypto collection of crates.
Contributions are welcome! Please follow these steps:
This project is licensed under the MIT License. See the LICENSE file for details.