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加密的更多相关文章

  1. 通过Go实现AES加密和解密工具

    本文包含如下两个内容: AES加密介绍及实现原理 Go实现AES加密和解密工具 AES加密介绍及实现原理 AES( advanced encryption standard)使用相同密钥进行加密和解密 ...

  2. golang AES/ECB/PKCS5 加密解密 url-safe-base64

    因为项目的需要用到golang的一种特殊的加密解密算法AES/ECB/PKCS5,但是算法并没有包含在标准库中,经过多次失败的尝试,终于解码成功,特此分享: /* 描述 : golang AES/EC ...

  3. 关于CryptoJS中md5加密以及aes加密的随笔

    最近项目中用到了各种加密,其中就包括从没有接触过得aes加密,因此从网上各种查,官方的一种说法: 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学 ...

  4. AES加密

    package com.edu.hpu; import java.math.BigInteger; import java.security.MessageDigest; import java.se ...

  5. Android数据加密之Aes加密

    前言: 项目中除了登陆,支付等接口采用rsa非对称加密,之外的采用aes对称加密,今天我们来认识一下aes加密. 其他几种加密方式: Android数据加密之Rsa加密 Android数据加密之Aes ...

  6. c#和js互通的AES加密解密

    一.使用场景 在使用前后端分离的框架中常常会进行传输数据相互加密解密以确保数据的安全性,如web Api返回加密数据客户端或web端进行解密,或者客户端或web端进行加密提交数据服务端解密数据等等. ...

  7. AES加密解密通用版Object-C / C# / JAVA

    1.无向量 128位 /// <summary> /// AES加密(无向量) /// </summary> /// <param name="plainByt ...

  8. nodejs与javascript中的aes加密

    简介 1.aes加密简单来说,在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用.高级加密标准已然成为对称密钥加 ...

  9. 非对称技术栈实现AES加密解密

    非对称技术栈实现AES加密解密 正如前面的一篇文章所述,https协议的SSL层是实现在传输层之上,应用层之下,也就是说在应用层上看到的请求还是明码的,对于某些场景下要求这些http请求参数是非可读的 ...

随机推荐

  1. UVALive - 7041 G - The Problem to Slow Down You

    题意:求两个串的公共回文子串个数 题解:建两个回文自动机,从0和1各跑一边就是答案了,因为对于回文自动机来说,从头开始dfs就能找出该字符串的所有回文串 //#pragma GCC optimize( ...

  2. leetcode-algorithms-11 Container With Most Water

    leetcode-algorithms-11 Container With Most Water Given n non-negative integers a1, a2, ..., an , whe ...

  3. spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient区别

    在使用服务发现的时候有两种注解, 一种为@EnableDiscoveryClient, 一种为@EnableEurekaClient, 用法上基本一致,下文是从stackoverflow上面找到的对这 ...

  4. django学习之——我的 Hello World

    pycharm 打开django 创建的项目:添加views.py文件 修改 urls.py from django.conf.urls import patterns, include, url f ...

  5. Segment set(线段并查集)

    Segment set Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total S ...

  6. 【转】JS常用函数整合库 lutils

    lutils 此工具包是在 outils 的基础上,加上个人平时收集的代码片段进行的二次整合 outils的GitHub:https://github.com/proYang/outils/blob/ ...

  7. Transactional参数说明

     参数  说明 readOnly 该属性用于设置当前事务是否为只读事务,设置为true表示只读,false则表示可读写,默认值为false.例如:@Transactional(readOnly=tru ...

  8. Vmware tools install

    Vmware tools 1◆ 下载 2◆ diagram   Ifcfg-eth0   =====>关闭防火墙 systemctl stop firewalld.service   ===== ...

  9. \x 和 0x 的区别

    1.0x 表示整型数值 (十六进制) char c = 0x42; 表示的是一个数值(字母B对应的ASCII码——  66),可以认为等价于: int c = 0x42; 2.\x42用于字符表达,或 ...

  10. Linux第二周作业

    通过反汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的 1.进入vi编写C语言程序代码,首先必须输入命令vi main,c,其中main.c是文件名. 紧接着按esc键退出编辑状态,再输入一个 ...