AES 加密和解密 [英] AES Encrypt and Decrypt
问题描述
我通过 swift 编写了一个应用程序,我需要 AES 加密和解密功能,我从另一个 .Net 解决方案收到了加密数据,但我找不到可以做的事情.
I write an application by swift, i need AES Encrypt and Decrypt functionality, i received encrypted data from another .Net solution, but i can't find something to do it.
这是我的 .net 加密:
This is my .net Encryption:
public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
{
byte[] encryptedBytes = null;
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
AES.KeySize = 256;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
return encryptedBytes;
}
我需要快速解密函数.
推荐答案
我找到了解决方案,它是一个很好的库.
I found the solution, it is a good library.
跨平台 256 位 AES 加密/解密.
Cross platform 256bit AES encryption / decryption.
该项目包含适用于所有平台(C#、iOS、Android)的 256 位 AES 加密的实现.关键目标之一是通过简单的实现使 AES 在所有平台上工作.
This project contains the implementation of 256 bit AES encryption which works on all the platforms (C#, iOS, Android). One of the key objective is to make AES work on all the platforms with simple implementation.
支持的平台:IOS ,安卓 ,Windows (C#).
Platforms Supported: iOS , Android , Windows (C#).
https://github.com/Pakhee/Cross-platform-AES-encryption
这篇关于AES 加密和解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!