GithubHelp home page GithubHelp logo

util's Introduction

composer install

composer require tinywan/util

加解密

加密

$key = '2024PpTJIR1aYFiFh0PppZzE';

// 加密内容
$content = [
    'name' => 'Tinywan',
    'school' => 'ZheJiang University',
    'age' => 24,
    'github' => [
        'home' => 'https://github.com/Tinywan',
        'start' => '6.8k',
    ],
];

// 必须转换为字符串
$dataJson = json_encode($content, JSON_UNESCAPED_UNICODE);
$decrypt = \tinywan\crypto\EncryptionUtil::encrypt($dataJson, $key);
var_dump($decrypt);

解密

$key = '2024PpTJIR1aYFiFh0PppZzE';

$decrypt = 'Dow1jTTBpriQUPLWFDli0BEjwn5Y3QG65TDWacyn/VRbxxxxxxxxxxxxxxxxd5ETvVbau4=';
$encrypt = \tinywan\crypto\EncryptionUtil::decrypt($decrypt, $key);
var_dump($encrypt);

SM4

// 32位key
$key = '4d7f2e7fe8e450385253bf379b13e432';

// 获取对应算法密码iv长度
$ivLength = openssl_cipher_iv_length(\tinywan\crypto\SM4Util::SM4_CBC);
$iv = (string) rand(pow(10, ($ivLength - 1)), pow(10, $ivLength) - 1);

// 加密字符串
$plaintext = '开源技术小栈';
$ciphertext = self::encrypt($plaintext, $key, $iv);
printf("加密结果1: %s\n", $ciphertext);
printf("解密结果2: %s\n", self::decrypt($ciphertext, $key, $iv));

util's People

Contributors

tinywan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.