encrypter

package module
v0.0.0-...-0a667e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 14 Imported by: 0

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
  1. 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.

  2. 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)
    }
    
  3. 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptArray

func DecryptArray(encryptedText, key string) (map[interface{}]interface{}, error)

func DecryptString

func DecryptString(encryptedText, key string) (string, error)

func EncryptArray

func EncryptArray(array interface{}, key string) (string, error)

func EncryptString

func EncryptString(plainText, key string) (string, error)

func PKCS7Padding

func PKCS7Padding(data []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(data []byte) ([]byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL