Discover Packages
github.com/RiniMisini12/laravelEncryption
package
module
Version:
v0.0.0-...-0a667e5
Opens a new window with list of versions in this module.
Published: Apr 29, 2025
License: MIT
Opens a new window with license information.
Imports: 14
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Laravel Encryption
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.
Features
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.
Installation
To install the package, simply run:
go get github.com/RiniMisini12/laravelEncryption
Usage
Full Laravel App Key Required
To use this package, you will need the full APP_KEY
from your Laravel application's .env
file. The key should be in base64
format, 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 the EncryptString
function and passing the string along with your Laravel APP_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 and APP_KEY
to the DecryptString
function:
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 EncryptArray
function:
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 DecryptArray
function:
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.
Expand ▾
Collapse ▴
Documentation
¶
func DecryptArray(encryptedText, key string) (map[interface{}]interface{}, error)
func DecryptString(encryptedText, key string) (string, error)
func EncryptArray(array interface{}, key string) (string, error)
func EncryptString(plainText, key string) (string, error)
func PKCS7Padding(data []byte, blockSize int) []byte
func PKCS7UnPadding(data []byte) ([]byte, error)
func DecryptArray(encryptedText, key string ) (map[interface{}]interface{}, error )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.