FlashSwirl 闪旋,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HASH、HMAC、HKDF、PBKDF2

发布时间:2026/10/7 2:20:20
FlashSwirl 闪旋,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HASH、HMAC、HKDF、PBKDF2 FlashSwirl 闪旋一款高性能的对称加密算法库提供流加密、AEAD认证加密、HASH、HMAC、HKDF、PBKDF2概述由风之暇想研究的对称加密算法基于ARXAdd-Rotate-XOR结构设计灵感来源于ChaCha20加密库提供流加密、AEAD认证加密、HASH、HMAC、HKDF密钥派生、PBKDF2密钥派生的密码学功能。✨ 特性多种加密模式支持流加密Stream和AEAD认证加密高性能设计批量处理、并行计算、内存池优化跨平台支持提供C、Go、JavaScript三种语言代码 算法规范算法规范文档 三种语言库调用说明C 版本使用示例#includeFlashSwirl.h#includeiostream#includevectorintmain(){// 准备密钥和Nonceuint8_tkey[32]{/* 32字节密钥 */};uint8_tnonce[24]{/* 24字节随机Nonce必须使用安全随机数生成 */};// 1. 流加密 std::vectoruint8_tdata{H,e,l,l,o};FlashSwirl_EncryptBuffer(key,32,nonce,24,data.data(),data.size(),20);// data现在包含密文FlashSwirl_DecryptBuffer(key,32,nonce,24,data.data(),data.size(),20);// data现在恢复为明文// 2. AEAD认证加密 uint8_tplaintext[]Secret message;uint8_tciphertext[256];intoutLensizeof(ciphertext);uint8_tad[]additional-data;FlashSwirl_EncryptAEADBuffer(key,32,nonce,24,plaintext,sizeof(plaintext)-1,ciphertext,outLen,ad,sizeof(ad)-1,20);uint8_tdecrypted[256];intplainLensizeof(decrypted);FlashSwirl_DecryptAEADBuffer(key,32,nonce,24,ciphertext,outLen,decrypted,plainLen,ad,sizeof(ad)-1,20);// 3. HASH constchar*messageHello, FlashSwirl!;uint8_thash[32];FlashSwirl_Hash((constuint8_t*)message,strlen(message),20,hash);// 4. HMAC uint8_thmacKey[]secret-key;uint8_thmacOut[32];FlashSwirl_HMAC(hmacKey,sizeof(hmacKey)-1,(constuint8_t*)message,strlen(message),20,hmacOut);// 5. HKDF密钥派生 uint8_tmasterKey[32]{/* 主密钥 */};uint8_tsalt[32]{/* 盐值 */};uint8_tinfo[]my-app;uint8_tderivedKey[32];FlashSwirl_HKDF(masterKey,32,salt,32,info,sizeof(info)-1,32,20,derivedKey);// 6. PBKDF2密钥派生 constchar*passworduser-password;uint8_tpbkdf2Salt[]random-salt;uint8_tkeyFromPassword[32];FlashSwirl_PBKDF2((constuint8_t*)password,strlen(password),pbkdf2Salt,sizeof(pbkdf2Salt)-1,10000,32,20,keyFromPassword);return0;}Go 版本https://pkg.go.dev/github.com/fzxx/FlashSwirl/GO/FlashSwirl使用示例packagemainimport(bytescrypto/randfmtFlashSwirl)funcmain(){// 准备密钥和Noncekey:make([]byte,32)nonce:make([]byte,24)rand.Read(key)rand.Read(nonce)// 1. 流加密 plaintext:[]byte(Secret message)varencrypted bytes.Buffer FlashSwirl.Encrypt(key,nonce,bytes.NewReader(plaintext),encrypted,20)vardecrypted bytes.Buffer FlashSwirl.Decrypt(key,nonce,encrypted,decrypted,20)fmt.Printf(Decrypted: %s\n,decrypted.Bytes())// 2. AEAD认证加密 varaeadEncrypted bytes.Buffer additionalData:[]byte(context info)FlashSwirl.EncryptAEAD(key,nonce,bytes.NewReader(plaintext),aeadEncrypted,additionalData,20)varaeadDecrypted bytes.Buffer valid,_:FlashSwirl.DecryptAEAD(key,nonce,aeadEncrypted,aeadDecrypted,additionalData,20)ifvalid{fmt.Printf(AEAD Decrypted: %s\n,aeadDecrypted.Bytes())}// 3. HASH message:[]byte(Hello, FlashSwirl!)hash,_:FlashSwirl.Hash(bytes.NewReader(message),20)fmt.Printf(Hash: %x\n,hash)// 4. HMAC hmacKey:[]byte(secret-key)hmacResult,_:FlashSwirl.HMAC(hmacKey,bytes.NewReader(message),20)fmt.Printf(HMAC: %x\n,hmacResult)// 5. HKDF密钥派生 salt:[]byte(random-salt)info:[]byte(my-app)derivedKey,_:FlashSwirl.HKDF(key,salt,info,32,20)fmt.Printf(Derived Key: %x\n,derivedKey)// 6. PBKDF2密钥派生 password:[]byte(user-password)pbkdf2Salt:[]byte(random-salt)keyFromPassword,_:FlashSwirl.PBKDF2(password,pbkdf2Salt,10000,32,20)fmt.Printf(Key from password: %x\n,keyFromPassword)}JavaScript 版本https://flashswirl.pages.dev/CDN引用script srchttps://cdn.jsdelivr.net/gh/fzxx/FlashSwirl/JS/FlashSwirl.js/scriptscript srchttps://cdn.statically.io/gh/fzxx/FlashSwirlmain/JS/FlashSwirl.js/script使用示例// 浏览器环境// script srcFlashSwirl.js/script// Node.js环境// const FlashSwirl require(./FlashSwirl.js);// 准备密钥和Nonceconstkeycrypto.getRandomValues(newUint8Array(32));constnoncecrypto.getRandomValues(newUint8Array(24));// 1. 流加密 constplaintextnewTextEncoder().encode(Secret message);constciphertextFlashSwirl.encrypt(stream,key,nonce,plaintext,newUint8Array(0),20);constdecryptedFlashSwirl.decrypt(stream,key,nonce,ciphertext,newUint8Array(0),20);console.log(Decrypted:,newTextDecoder().decode(decrypted));// 2. AEAD认证加密 constadditionalDatanewTextEncoder().encode(context info);constaeadCiphertextFlashSwirl.encrypt(aead,key,nonce,plaintext,additionalData,20);constaeadDecryptedFlashSwirl.decrypt(aead,key,nonce,aeadCiphertext,additionalData,20);console.log(AEAD Decrypted:,newTextDecoder().decode(aeadDecrypted));// 3. HASH constmessagenewTextEncoder().encode(Hello, FlashSwirl!);consthashFlashSwirl.hash(message,20);console.log(Hash:,Array.from(hash).map(bb.toString(16).padStart(2,0)).join());// 4. HMAC consthmacKeynewTextEncoder().encode(secret-key);consthmacResultFlashSwirl.hmac(hmacKey,message,20);console.log(HMAC:,Array.from(hmacResult).map(bb.toString(16).padStart(2,0)).join());// 5. HKDF密钥派生 constsaltnewTextEncoder().encode(random-salt);constinfonewTextEncoder().encode(my-app);constderivedKeyFlashSwirl.hkdf(key,salt,info,32,20);console.log(Derived Key:,Array.from(derivedKey).map(bb.toString(16).padStart(2,0)).join());// 6. PBKDF2密钥派生 constpasswordnewTextEncoder().encode(user-password);constpbkdf2SaltnewTextEncoder().encode(random-salt);constkeyFromPasswordFlashSwirl.pbkdf2(password,pbkdf2Salt,10000,32,20);console.log(Key from password:,Array.from(keyFromPassword).map(bb.toString(16).padStart(2,0)).join());‍开源地址https://github.com/fzxx/FlashSwirl/ 更新日志更新日志许可证GNU General Public License 3.0

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询