秘钥简单使用

密钥登录SSH服务器

进入服务端,先编辑SSH配置文件

vim /etc/ssh/sshd_config

找到这一行前面#注释删除

然后重启httpd服务

systemctl restart httpd

 进入客户端,生成ssh登陆的密钥对

 查看生成的密钥是否是新生成的

然后把刚刚生成的/root/.ssh/id_rsa.pub文件下载下来放入服务端,把id_rsa也下载了

 进入服务端,将公钥文件输出到服务器配置文件中

然后进入客户端登陆

 显示下面一条就成功了,再去finalshell新建一个ssh连接

选择私钥链接就来找到文件就行

OPENSSL简单使用

先去创建一个文件,用于被加密,内容为12345,文件名为test.txt

echo 12345 >test.txt

 然后使用rc4加解密 ,加密

openssl enc -e -rc4 -in test.txt -out test_rc4.enc

输入密码

解密

openssl enc -d -rc4 -in test_rc4.enc -out test_rc4.dm

使用AES加解密

加密

openssl enc -e -aes-128-cbc -a -salt -in test.txt -out test_aes128.enc

解密

openssl enc -d -aes-128-cbc -a -salt -in test_aes128.enc -out test_aes128.d

RSA加解密码

生成RSA密钥对
openssl genrsa -out rsa.key 1024

 导出公钥
openssl rsa -in rsa.key -pubout -out rsa_pub.key

 使用公钥加密文件
openssl rsautl -encrypt -in test.txt -inkey rsa_pub.key -pubin -out test_rsa.enc
 使用私解解密文件
openssl rsautl -decrypt -in test_rsa.enc -inkey rsa.key -out test_rsa.c

使用公钥解密报错
openssl rsautl -decrypt -in test_rsa.enc -inkey rsa_pub.key -out test_rsa.c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 SM2 的公钥和私钥进行加解密或签名验签,需要使用 SM2 算法库来实现。下面是一个简单的示例代码,假设你已经有了十六进制格式的公钥和私钥: ```python from gmssl import sm2, func # 16进制格式的公钥和私钥 public_key = '043C53D14C2E5A8EB8C9D0C7F03D6F2B99A732D2B8A07B5B0B48493E4D8E56E3B4FCEB9D3F37D2E21CF9D2A8D7F3B1D7AF20B9E2D508AFB97FF3C9EC8B59B381' private_key = '3B6C734F9882B9E01D9E4A7A12C2A8E1FFC8ECD2C1E6B9B44B6D5ADA2B9E65E6' # 使用公钥加密 plain_text = b'Hello, world!' cipher_text, _ = sm2.encrypt(func.bytes_to_list(plain_text), public_key) print('Cipher text:', cipher_text) # 使用私钥解密 plain_text = bytes(sm2.decrypt(cipher_text, func.hex_to_bytes(private_key))) print('Plain text:', plain_text) # 使用私钥签名 signature = sm2.sign(plain_text, private_key, None) print('Signature:', signature) # 使用公钥验签 verify_result = sm2.verify(plain_text, signature, public_key, None) print('Verify result:', verify_result) ``` 在这个示例中,我们使用 gmssl 库来实现 SM2 算法。首先将十六进制格式的公钥和私钥转换为字节串,然后使用 `sm2.encrypt()` 函数使用公钥加密明文,使用 `sm2.decrypt()` 函数使用私钥解密密文。使用 `sm2.sign()` 函数使用私钥对明文签名,使用 `sm2.verify()` 函数使用公钥验证签名。注意,在验证签名时,需要提供与签名时使用的哈希函数相同的哈希算法名称(例如,如果签名时使用的是 SM3 哈希函数,则在验证时也需要指定为 SM3)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值