Golang AES加密
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
"os"
)
var commonIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
func main() {
//password length must be under 30
password := []byte("thisisthepassword")
//key string
key := "s8*WQ0@KO#CN*raoua8ofCTx*oxqCk46"
ciphercode := Encrypt(key, password)
Decrypt(key, ciphercode)
}
func Encrypt(key string, password []byte) []byte {
//create aes
c, err := aes.NewCipher([]byte(key))
if err != nil {
fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key), err)
os.Exit(-1)
}
//encrypt string
cfb := cipher.NewCFBEncrypter(c, commonIV)
ciphertext := make([]byte, len(password))
cfb.XORKeyStream(ciphertext, password)
return ciphertext
}
func Decrypt(key string, ciphercode []byte) []byte {
//create aes
c, err := aes.NewCipher([]byte(key))
if err != nil {
fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key), err)
os.Exit(-1)
}
//decrypt string
cfbdec := cipher.NewCFBDecrypter(c, commonIV)
password := make([]byte, 30)
cfbdec.XORKeyStream(password, ciphercode)
return password
}
Golang AES加密的更多相关文章
- 通过Go实现AES加密和解密工具
本文包含如下两个内容: AES加密介绍及实现原理 Go实现AES加密和解密工具 AES加密介绍及实现原理 AES( advanced encryption standard)使用相同密钥进行加密和解密 ...
- golang AES/ECB/PKCS5 加密解密 url-safe-base64
因为项目的需要用到golang的一种特殊的加密解密算法AES/ECB/PKCS5,但是算法并没有包含在标准库中,经过多次失败的尝试,终于解码成功,特此分享: /* 描述 : golang AES/EC ...
- 关于CryptoJS中md5加密以及aes加密的随笔
最近项目中用到了各种加密,其中就包括从没有接触过得aes加密,因此从网上各种查,官方的一种说法: 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学 ...
- AES加密
package com.edu.hpu; import java.math.BigInteger; import java.security.MessageDigest; import java.se ...
- Android数据加密之Aes加密
前言: 项目中除了登陆,支付等接口采用rsa非对称加密,之外的采用aes对称加密,今天我们来认识一下aes加密. 其他几种加密方式: Android数据加密之Rsa加密 Android数据加密之Aes ...
- c#和js互通的AES加密解密
一.使用场景 在使用前后端分离的框架中常常会进行传输数据相互加密解密以确保数据的安全性,如web Api返回加密数据客户端或web端进行解密,或者客户端或web端进行加密提交数据服务端解密数据等等. ...
- AES加密解密通用版Object-C / C# / JAVA
1.无向量 128位 /// <summary> /// AES加密(无向量) /// </summary> /// <param name="plainByt ...
- nodejs与javascript中的aes加密
简介 1.aes加密简单来说,在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用.高级加密标准已然成为对称密钥加 ...
- 非对称技术栈实现AES加密解密
非对称技术栈实现AES加密解密 正如前面的一篇文章所述,https协议的SSL层是实现在传输层之上,应用层之下,也就是说在应用层上看到的请求还是明码的,对于某些场景下要求这些http请求参数是非可读的 ...
随机推荐
- getopt实现传参自动识别
test.py #!/usr/bin/env python # -*- coding: utf-8 -*- import getopt import sys #-h-f-v为了下面的识别 opts,a ...
- leetcode-algorithms-21 Merge Two Sorted Lists
leetcode-algorithms-21 Merge Two Sorted Lists Merge two sorted linked lists and return it as a new l ...
- PAT 1019 General Palindromic Number
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- Leetcode 1029. 可被 5 整除的二进制前缀
1029. 可被 5 整除的二进制前缀 显示英文描述 我的提交返回竞赛 用户通过次数467 用户尝试次数662 通过次数477 提交次数1964 题目难度Easy 给定由若干 0 和 1 组成的 ...
- UI基础一:简单的BOL查询
利用标准的BOL编辑工具,添加BOL对象,重写查询方法,实现简答的BOL查询 1.SE11创建查询对象结构: 2.SE11创建查询结果对象: 3.SE24新建处理类: 重写查询结果方法: METHOD ...
- 46. Permutations C++回溯法
基本的回溯法 注意每次回溯回来要把上次push_back()进去的数字pop掉! class Solution { public: void backTrack(vector<int> n ...
- zzw原创_oracle循环中的异常捕捉_捕捉异常后并继续循环
例子如下 set serveroutput on; declare V_SQL VARCHAR2(255); errorCode number; --异常编码 errorMsg var ...
- 如何解决Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a. 问题
在系统中需要把数据导出到excel并且压缩,然后报了这个问题: 我在网站上找到了方法: 地址:https://social.msdn.microsoft.com/Forums/vstudio/en-U ...
- PHPCMS V9完全开发介绍
PHPCMS V9 文件目录结构: 根目录 | – api 接口文件目录 | – caches 缓存文件目录 | – configs 系统配置文件目录 | – caches_* 系统缓存目录 | – ...
- Linux登录超时自动退出处理办法
出于安全方面的考虑,机器常要求配置一个登录时间期限,当闲置超过这一期限就自动退出:但在某些场合我们需要时不时地就使用机器,如果每次都要重新ssh登录那是非常麻烦的 方法一:让当前会话一直处于工作状态 ...