happ

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

README

This module is designed for authorized use only. It operates under the assumption that you, the user, have legally obtained the necessary private keys or access credentials directly from the official developers or service administrators.

  • We do not possess, provide, or assist in obtaining any private keys, credentials, or access tokens.
  • Attempting to acquire such keys without explicit authorization from the rightful owners is likely illegal and constitutes a violation of computer fraud and abuse laws, terms of service, and copyright.
  • This project is intended solely for developers and users who have been explicitly granted access by the official source.

The maintainers of this repository are not responsible for any misuse, legal repercussions, or damages resulting from unauthorized use of this software.

Happ Encryption/Decryption Module

A Go module for encrypting and decrypting Happ links using RSA encryption with PKCS1v15 padding.

Features

  • 🔐 RSA encryption/decryption with PKCS1v15 padding
  • 🔗 All Happ link format support (happ://crypt/..., happ://crypt2/..., happ://crypt3/...)
  • 🗝️ Multiple key version support
  • 🛡️ Comprehensive error handling

Installation

go get github.com/nf776/happ-decryptor@v1.0.0

Usage

package main

import (
    "fmt"
    "log"
    "github.com/nf776/happ-decryptor"
)

func main() {
    // Initialize keys
    privateKeys := map[string]string {
        "crypt":  "keys/private_crypt.pem",
        "crypt2": "keys/private_crypt2.pem",
        "crypt3": "keys/private_crypt3.pem",
    }

    publicKeys := map[string]string {
        "crypt":  "keys/public_crypt.pem",
        "crypt2": "keys/public_crypt2.pem",
        "crypt3": "keys/public_crypt3.pem",
    }

    // Initialize processor with key paths
    processor, err := happ.New(privateKeys, publicKeys)
    if err != nil {
        log.Fatal(err)
    }

    // Encrypt data
    result, err := processor.Encrypt("secret data", "crypt3")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Encrypted link: %s\n", result.Link)

    // Decrypt data
    decrypted, err := processor.Decrypt(result.Link)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Decrypted data: %s\n", decrypted.DecryptedData)
    fmt.Printf("Used key: %s\n", decrypted.UsedKey)
}

Key Requirements

  • Private Keys: For decryption (keys from app)
  • Public Keys: For encryption (PKCS8 PEM format)
  • Key Versions: Support for crypt, crypt2, crypt3 versions

Error Handling

The module provides comprehensive error handling with clear error messages:

result, err := processor.Encrypt("data", "unknown")
if err != nil {
    switch err.Error() {
    case happ.ErrEmptyPath:
        // Handle missing path
    case happ.ErrPrivateKeyNotRSA:
        // Handle private key error
    // ... other cases
    }
}

Smart Decryption

  • Automatically tries multiple key versions if the specified one fails
  • Fallback order: specified version → crypt → crypt2 → crypt3
  • Returns the actual key used for decryption

Documentation

Index

Constants

View Source
const (
	ErrEmptyPath            = "path cannot be empty"
	ErrFileRead             = "failed to read file"
	ErrFileEmpty            = "file is empty"
	ErrPEMDecode            = "failed to decode PEM"
	ErrPEMNil               = "PEM block is nil"
	ErrPrivateKeyNotRSA     = "private key is not an RSA private key"
	ErrPublicKeyNotRSA      = "public key is not an RSA private key"
	ErrPrivateKeyParse      = "private key parse error"
	ErrPrivateKeyNil        = "private key is nil"
	ErrPublicKeyParse       = "public key parse error"
	ErrPublicKeyNil         = "public key is nil"
	ErrEmptyData            = "data is empty"
	ErrEmptyVersion         = "version cannot be empty"
	ErrDecryptEmptyLink     = "empty link"
	ErrDecryptBadData       = "none of the keys could decrypt the data"
	ErrWrongVersion         = "public key for version %s not found"
	ErrWrongKeyForVersion   = "public key for version %s is invalid (nil)"
	ErrInvalidLinkFormat    = "invalid link format"
	ErrEncryptedDataIsEmpty = "encrypted data is empty"
	ErrB64Decode            = "base64 decode fails: %v"
	ErrRSADecode            = "RSA decode fails: %v"
	ErrLargeData            = "data too large"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func New

func New(privateKeyPaths map[string]string, publicKeyPaths map[string]string) (*Processor, error)

func (*Processor) Decrypt

func (p *Processor) Decrypt(link string) (Result, error)

func (*Processor) Encrypt

func (p *Processor) Encrypt(data, version string) (Result, error)

type Result

type Result struct {
	Version       string
	UsedKey       string
	EncryptedData string
	DecryptedData string
	Link          string
}

Jump to

Keyboard shortcuts

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