承接 sham3r/cipher-bsk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sham3r/cipher-bsk

Composer 安装命令:

composer require sham3r/cipher-bsk

包简介

A lightweight encryption library implementing techniques from the research paper 'A Hybrid Cryptographic Scheme of Modified Vigenère Cipher using Randomized Approach for Enhancing Data Security' by Sazzad Saju. This library provides robust data security with secure hashing capabilities and Laravel-n

README 文档

README

Bornomala Symmetric Key (BSK) stream cipher, is a lightweight encryption library implementing techniques from the research paper 'A Hybrid Cryptographic Scheme of Modified Vigenère Cipher using Randomized Approach for Enhancing Data Security' by Sazzad Saju. This library aims to provide robust data security with an easy-to-use API. For more details, visit: https://bit.ly/cipher-bsk

🔐 New in v1.1.1

  • Added secureHash() and verifyHash() for dual-layer password encryption.
  • Added Laravel integration (config, service provider, and facade).
  • Backward compatible with v1.0.

Installation/Launch

Install the package via Composer:

composer require sham3r/cipher-bsk

Usage

Basic Encryption/Decryption (Existing functionality)

<?php
require 'vendor/autoload.php';
use CipherBsk\CipherBsk;

$message = "Hajee Mohammad Danesh Science and Technology University";
$key = "Hstu@5200";

$cipherBsk = new CipherBsk();

$encryptedMessage = $cipherBsk->encrypt($message, $key);
echo "Encrypted Message: $encryptedMessage\n";

$decryptedMessage = $cipherBsk->decrypt($encryptedMessage, $key);
echo "Decrypted Message: $decryptedMessage\n";

// Example output:
// Encrypted Message: 7B4D5249784F285E6433232166594C6A5A5A3322532A7C4E4F72697D2B4C52515F7400753644674061576C254E47724635612920714C6A21
// Decrypted Message: Hajee Mohammad Danesh Science and Technology University

🆕 Secure Password Hashing (v1.1.1)

Note: You must set an environment variable for secure hashing:

<?php
require 'vendor/autoload.php';
use CipherBsk\CipherBsk;

// Set environment variable for key (REQUIRED)
putenv('CIPHER_BSK_KEY=Hstu@5200');
// OR use APP_KEY
putenv('APP_KEY=your-application-key');

$cipherBsk = new CipherBsk();

// Hash a password with dual-layer encryption
$password = "mysecretpassword";
$hashedPassword = $cipherBsk->secureHash($password);
echo "Hashed Password: $hashedPassword\n";

// Verify password
$isValid = $cipherBsk->verifyHash($password, $hashedPassword);
echo "Password Valid: " . ($isValid ? "Yes" : "No") . "\n";

// Wrong password verification
$isInvalid = $cipherBsk->verifyHash("wrongpassword", $hashedPassword);
echo "Wrong Password Valid: " . ($isInvalid ? "Yes" : "No") . "\n";

🆕 Laravel Integration (v1.1.1)

Auto-Discovery Setup

The package automatically registers itself in Laravel applications. No manual setup required!

Using the Facade:

<?php
use CipherBsk;

// Basic encryption/decryption
$message = "Hello, World!";
$key = "Hstu@5200";

$encrypted = CipherBsk::encrypt($message, $key);
$decrypted = CipherBsk::decrypt($encrypted, $key);

// Secure password hashing (uses your Laravel config)
$hash = CipherBsk::secureHash('Hstu@5200');
dd(CipherBsk::verifyHash('Hstu@5200', $hash)); // true

$wrongHash = CipherBsk::verifyHash('wrongpassword', $hash);
dd($wrongHash); // false

Laravel Configuration:

  1. Publish the config file (optional):
php artisan vendor:publish --tag=config
  1. Set your environment variables in .env:
# Option 1: Use dedicated cipher key
CIPHER_BSK_KEY=your-secret-cipher-key

# Option 2: Use your existing APP_KEY (fallback)
APP_KEY=base64:your-laravel-app-key
  1. Configuration file (config/cipher-bsk.php):
<?php
return [
    'key' => env('CIPHER_BSK_KEY', env('APP_KEY')),
];

Laravel Service Container:

<?php
// Inject via service container
class UserController extends Controller
{
    public function hashPassword(Request $request, CipherBsk $cipher)
    {
        $password = $request->input('password');
        $hash = $cipher->secureHash($password);
        
        // Store $hash in database
        User::create(['password' => $hash]);
        
        return response()->json(['success' => true]);
    }
    
    public function verifyPassword(Request $request, CipherBsk $cipher)
    {
        $user = User::find($request->user_id);
        $inputPassword = $request->input('password');
        
        $isValid = $cipher->verifyHash($inputPassword, $user->password);
        
        return response()->json(['valid' => $isValid]);
    }
}

Features

  • Avalanche effect - Small changes in input create large changes in output
  • Immune from frequency analysis attack - Secure against cryptographic attacks
  • Output ranges from ASCII(0-255) - Full character space utilization
  • 🆕 Dual-layer password hashing (CipherBSK + bcrypt) - Enhanced security
  • 🆕 Laravel integration with auto-discovery - Seamless framework integration
  • 🆕 Environment-based key management - Secure configuration
  • Backward compatible with existing code - No breaking changes

Important Security Notes

For Secure Hashing Features

  • MUST set CIPHER_BSK_KEY or APP_KEY environment variable
  • Never commit keys to version control
  • Use different keys for different environments (dev, staging, production)

Example Environment Setup:

# In your .env file
CIPHER_BSK_KEY=your-long-random-secret-key-here

# Or use existing Laravel APP_KEY
APP_KEY=base64:generated-laravel-key

Error Handling:

If no key is configured, the package will throw a RuntimeException with helpful instructions:

No encryption key configured. Please set one of the following environment variables: 
CIPHER_BSK_KEY or APP_KEY. 
For Laravel projects: run "php artisan vendor:publish --tag=config" to publish the config file.

Compatibility

Existing Users (v1.0.x)

All existing code continues to work without changes:

// This still works exactly the same
$cipher = new CipherBsk();
$encrypted = $cipher->encrypt($message, $key);
$decrypted = $cipher->decrypt($encrypted, $key);

New Users (v1.1.1+)

Access to both original and new features:

// Original features
$cipher = new CipherBsk();
$encrypted = $cipher->encrypt($message, $key);

// New secure hashing (requires environment key)
putenv('CIPHER_BSK_KEY=your-key');
$hash = $cipher->secureHash($password);
$isValid = $cipher->verifyHash($password, $hash);

Documentation

Testing

Run All Tests:

vendor/bin/phpunit --testdox

Test Specific Features:

# Test basic encryption/decryption
vendor/bin/phpunit tests/CipherBskTest.php --testdox

# Test secure hashing features
vendor/bin/phpunit tests/SecureHashTest.php --testdox

# Test key generation
vendor/bin/phpunit tests/KeyGeneratorTest.php --testdox

Test Coverage:

  • 25 tests total - Comprehensive coverage
  • 71 assertions - Thorough validation
  • Core encryption - Original CipherBSK algorithm
  • Secure hashing - New dual-layer password security
  • Environment handling - Key resolution and error cases
  • Laravel integration - Framework-specific features

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (vendor/bin/phpunit)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

Acknowledgments

  • Based on the research paper: "A Hybrid Cryptographic Scheme of Modified Vigenère Cipher using Randomized Approach for Enhancing Data Security"
  • Hajee Mohammad Danesh Science and Technology University
  • Laravel community for framework integration patterns

sham3r/cipher-bsk 适用场景与选型建议

sham3r/cipher-bsk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「cryptography」 「hash」 「encryption」 「laravel」 「cipher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sham3r/cipher-bsk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sham3r/cipher-bsk 我们能提供哪些服务?
定制开发 / 二次开发

基于 sham3r/cipher-bsk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-28