惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
B
Blog RSS Feed
I
InfoQ
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏

会走路的三百块

会走路的三百块 会走路的三百块 其他 | 会走路的三百块 会走路的三百块 Unity-业务框架 | 会走路的三百块 其他 | 会走路的三百块 part 4 踩坑记录 | 会走路的三百块 Unity-进阶知识 | 会走路的三百块 Unity-天命6源码 | 会走路的三百块 CICD | 会走路的三百块 part 1 linux的历史节点 | 会走路的三百块 C的编译器 | 会走路的三百块 字符串常量存储 | 会走路的三百块 第三章 数据和C | 会走路的三百块 类型转换和缩减 | 会走路的三百块 零散知识点 | 会走路的三百块 DNS选择机制 | 会走路的三百块 网络八股Cache | 会走路的三百块 第三章-数据和C | 会走路的三百块 一些零散的知识点 | 会走路的三百块 自顶向下 | 会走路的三百块 linux简单速通 | 会走路的三百块 设计图的概述 | 会走路的三百块 AI和自动化暂存 | 会走路的三百块 第一章 初识C语言 | 会走路的三百块 Games101 | 会走路的三百块 Unity-Lua补充 | 会走路的三百块 Unity-个人Demo | 会走路的三百块 Unity-基础知识 | 会走路的三百块 Unity环境搭建 | 会走路的三百块
后端常见安全措施 | 会走路的三百块
2026-05-25 · via 会走路的三百块

后端常见安全措施 ​

创建于 2024年5月28日 01:32:22 · 约429字

这里并不是专门做安全的专业的,而是作为一个开发人员应该了解的安全方面。

服务器安全 ​

POST 为什么会发送两次请求 同源策略以及规避

SSH审计工具jtesta/ssh-audit 可以看主机的SSH安全策略和漏洞

小团队VPN和防火墙选型 ​

#todo 几人的小团队使用的软件VPN和防火墙,原则是持久不过期,能一直用,安全性够用就行。还有防火墙的软硬件区别

后端常用加密解密 ​

#todo 关于常见的加密解密,非安全开发者应该知道的方法,性能,安全性,哪些部分可公开 常用的整个表格

AES加密解密,和通用公司对接的时候要求用户名和密码都加密传输,所以前端需要从可信服务器搞密钥,然后进行加密传后端之后解密

使用XOR ​

这是一种简单的加密方式,加密出来也不会太长,适合加密身份证等有点重要但是又没那么重要的,前面显示的是密文,后端拿到手动解密出来。几乎不会性能造成瓶颈。
以后写详细的东西,先把代码放出来。

python

# -*- coding: utf-8 -*-  
import binascii  
  
# XOR加密函数,返回十六进制字符串  
def xor_encrypt(data: str, key: str) -> str:  
    key_bytes = key.encode('utf-8')  
    encrypted_data = bytearray()  
  
    # XOR操作  
    for i, char in enumerate(data):  
        encrypted_data.append(ord(char) ^ key_bytes[i % len(key_bytes)])  
  
    # 将加密数据转换为十六进制字符串  
    return binascii.hexlify(bytes(encrypted_data)).decode('utf-8')  
  
  
# XOR解密函数,接受十六进制字符串  
def xor_decrypt(encrypted_data: str, key: str) -> str:  
    encrypted_data_bytes = binascii.unhexlify(encrypted_data)  
    key_bytes = key.encode('utf-8')  
    decrypted_data = ""  
  
    # XOR解密操作  
    for i, byte in enumerate(encrypted_data_bytes):  
        decrypted_data += chr(byte ^ key_bytes[i % len(key_bytes)])  
  
    return decrypted_data  
  
  
# 加密身份证号的函数  
def encrypt_idnum(idnum: str, key: str) -> str:  
    if len(idnum) != 18:  
        raise ValueError("身份证号码必须为18位")  
  
    # 获取第7到第18位  
    idcard_to_encrypt = idnum[6:18]  
  
    # 加密第7到第18位  
    encrypted_part = xor_encrypt(idcard_to_encrypt, key)  
  
    # 返回加密后的身份证号码 (前6位 + 加密部分 + 后4位)  
    encrypted_idcard = idnum[:6] + encrypted_part + idnum[18:]  
    return encrypted_idcard  
  
  
# 解密身份证号的函数  
def decrypt_idnum(encrypted_idnum: str, key: str) -> str:  
    if len(encrypted_idnum) < 18:  
        raise ValueError("加密后的身份证号码长度不正确")  
  
    # 获取加密部分的长度  
    encrypted_part_length = (len(encrypted_idnum) - 6)  # 4是后4位身份证号(年份等)  
  
    # 获取加密后的部分  
    encrypted_part = encrypted_idnum[6:6 + encrypted_part_length]  
  
    # 解密加密部分  
    decrypted_part = xor_decrypt(encrypted_part, key)  
  
    # 返回解密后的身份证号码(前6位 + 解密部分 + 后4位)  
    decrypted_idcard = encrypted_idnum[:6] + decrypted_part  
    return decrypted_idcard  
  
  
# # 示例使用  
# idcard = "123456199012345678"  # 身份证号  
idnum_secret_key = "rL?viM3^zqp+Er!k~2"  # 密钥  
#  
# # 加密  
# encrypted_idcard = encrypt_idnum(idcard, idnum_secret_key)  
# print(f"Encrypted IDCard: {encrypted_idcard}")  
#  
# # 解密  
# decrypted_idcard = decrypt_idnum(encrypted_idcard, idnum_secret_key)  
# print(f"Decrypted IDCard: {decrypted_idcard}")
  • crypto是老的GPG加解密库已于2016年停更,python-gnupg库是目前最主流的GPG加解密库
  • PyCrypto是前主流加解密库已停更。PyCryptodome是当前最主流的Python加解密库,代码中有import Crypto等就需要用这个库
  • cryptography 是 PyCA (Python Cryptographic Authority)维护的库,默认就使用行业标准方案维护频率高强调安全

SSH