The base64encryption package provides simple methods for encrypting and decrypting strings using base64 encoding along with a basic XOR-based obfuscation technique. This package is useful for scenarios where you need to securely encode and decode sensitive information with a key.
To use this package, you need to include it in your Go module. If you're using Go modules, you can add it to your project with:
go get github.com/nawawi/go-base64encryptionimport it as "github.com/nawawi/go-base64encryption", use it as base64encryption.
import "github.com/nawawi/go-base64encryption"You can create a new instance of Base64Encryption with or without a secret key:
// Create a new instance with a provided key
be := base64encryption.NewBase64Encryption("mySecretKey")
// Create a new instance with an empty key, which will use the default key from the environment variable
be := base64encryption.NewBase64Encryption("")Encrypt a string with a key:
encrypted := be.Encrypt("mySensitiveData", "mySecretKey")If you do not provide a key, the instance's key will be used:
encrypted := be.Encrypt("mySensitiveData", "")Decrypt an encrypted string with a key:
decrypted := be.Decrypt(encrypted, "mySecretKey")if you do not provide a key, the instance's key will be used:
decrypted := be.Decrypt(encrypted, "")You can set a new prefix and key for encryption:
be.setPrefix("newPrefix")
be.setKey("newSecretKey")To check if a value is encrypted:
isEncrypted := be.isEncrypted(encryptedValue)To run the tests for this package, use:
go testThe tests will check the functionality of encryption, decryption, setting keys and prefixes, and more.
This package is open-source and available under the MIT License.
Contributions are welcome! Please fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
For support or questions, please open an issue on the GitHub repository