A Go package that provides encryption and decryption for strings and arrays identical to Laravel's Encrypter. This package is perfect for securely sharing encrypted data between Go applications and Laravel backends.
- Encrypt and decrypt strings in a way that is fully compatible with Laravel's encryption.
- Encrypt and decrypt arrays (or any serializable data) using Laravel's encryption format.
To install the package, simply run:
go get github.com/RiniMisini12/laravelEncryption-
Full Laravel App Key Required
To use this package, you will need the fullAPP_KEYfrom your Laravel application's.envfile. The key should be inbase64format, and you can pass it directly to the functions provided by this package. -
Encryption and Decryption of Strings
Encrypting a String
You can encrypt a string by using theEncryptStringfunction and passing the string along with your LaravelAPP_KEY:package main import ( "fmt" "log" "github.com/RiniMisini12/laravel-encryption" ) func main() { appKey := "base64:YOUR_APP_KEY" encryptedString, err := encrypter.EncryptString("My secret data", appKey) if err != nil { log.Fatalf("Error encrypting string: %v", err) } fmt.Println("Encrypted string:", encryptedString) }
Decrypting a String
To decrypt the string, pass the encrypted text andAPP_KEYto theDecryptStringfunction:package main import ( "fmt" "log" "github.com/RiniMisini12/laravel-encryption" ) func main() { appKey := "base64:YOUR_APP_KEY" encryptedString := "ENCRYPTED_TEXT_HERE" decryptedString, err := encrypter.DecryptString(encryptedString, appKey) if err != nil { log.Fatalf("Error decrypting string: %v", err) } fmt.Println("Decrypted string:", decryptedString) }
-
Encryption and Decryption of Arrays
Encrypting an Array You can encrypt arrays (or any serializable data) by passing them to the
EncryptArrayfunction:package main import ( "fmt" "log" "github.com/RiniMisini12/laravel-encryption" ) func main() { appKey := "base64:YOUR_APP_KEY" arrayToBeEncrypted := []string{"item1", "item2", "item3"} encryptedArray, err := encrypter.EncryptArray(arrayToBeEncrypted, appKey) if err != nil { log.Fatalf("Error encrypting array: %v", err) } fmt.Println("Encrypted array:", encryptedArray) }
Decrypting an Array To decrypt an encrypted array, use the
DecryptArrayfunction:package main import ( "fmt" "log" "github.com/RiniMisini12/laravel-encryption" ) func main() { appKey := "base64:YOUR_APP_KEY" encryptedArray := "ENCRYPTED_ARRAY_HERE" decryptedArray, err := encrypter.DecryptArray(encryptedArray, appKey) if err != nil { log.Fatalf("Error decrypting array: %v", err) } fmt.Println("Decrypted array:", decryptedArray) }
This project is licensed under the MIT License. See the LICENSE file for details.