【问题标题】:is there AES source code (VB.NET) that decrypts AS3CRYPTO crypted msgs是否有解密 S3 CRYPTO 加密消息的 AES 源代码 (VB.NET)
【发布时间】:2010-10-13 02:40:39
【问题描述】:

是否有可用于 AES 加密的简单 ASP.NET (.VB)?

这是一个指向 c# 的链接,但它的复杂性有很多参数,例如盐。 [http://www.gutgames.com/post/AES-Encryption-in-C.aspx]

我需要一个与 GOOGLEAS3 类一起工作的简单类,像这样轻松调用:

var key:ByteArray = Hex.toArray("1234567890abcdef");
var pt:ByteArray = Hex.toArray( Hex.fromString("aaaaaaaaaaaaaaaaaaaa"));
var aes:AESKey = new AESKey(key);
aes.encrypt(pt);
var out:String = Hex.fromArray(pt).toUpperCase();

【问题讨论】:

    标签: asp.net vb.net encryption


    【解决方案1】:

    AES 内置在框架中,作为 System.Security.Cryptography 中的Aes 类。有两种具体的实现,一种是托管的,一种是使用 Windows Crypto Service Provider(速度更快,但不能移植到其他平台)。还有一个Rijndael 的实现,AES 就是从该实现中派生出来的。

    请记住,您需要一个初始化向量以及加密/解密的密钥,因为它是一个分组密码。如果您在未设置的情况下进行加密,则将使用随机一个,但您需要存储和检索它以进行解密。

    示例代码:(摘自我即将出版的书 grin 的第 6 章)

    static byte[] Encrypt(byte[] clearText, byte[] key, byte[] iv)
    {
        // Create an instance of our encyrption algorithm.
        RijndaelManaged rijndael = new RijndaelManaged();
    
        // Create an encryptor using our key and IV
        ICryptoTransform transform = rijndael.CreateEncryptor(key, iv);
    
        // Create the streams for input and output
        MemoryStream outputStream = new MemoryStream();
        CryptoStream inputStream = new CryptoStream(
            outputStream,
            transform,
            CryptoStreamMode.Write);
    
        // Feed our data into the crypto stream.
        inputStream.Write(clearText, 0, clearText.Length);
    
        // Flush the crypto stream.
        inputStream.FlushFinalBlock();
    
        // And finally return our encrypted data.
        return outputStream.ToArray();
    }
    

    解密

    static byte[] Decyrpt(byte[] clearText, byte[] key, byte[] iv)
    {
        // Create an instance of our encryption algorithm.
        RijndaelManaged rijndael = new RijndaelManaged();
    
        // Create an decryptor using our key and IV
        ICryptoTransform transform = rijndael.CreateDecryptor(key, iv);
    
        // Create the streams for input and output
        MemoryStream outputStream = new MemoryStream();
        CryptoStream inputStream = new CryptoStream(
            outputStream,
            transform,
            CryptoStreamMode.Write);
    
        // Feed our data into the crypto stream.
        inputStream.Write(clearText, 0, clearText.Length);
    
        // Flush the crypto stream.
        inputStream.FlushFinalBlock();
    
        // And finally return our decrypted data.
        return outputStream.ToArray();
    }
    

    将 RijndaelManaged 类替换为 AES 类之一和合适的密钥。

    【讨论】:

    • 我正在尝试这样做,但我不断收到密钥大小违规。这是我的密钥: stringverySecureKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";当我这样做时: var algo = new System.Security.Cryptography.RijndaelManaged(); keyArray = UTF8Encoding.UTF8.GetBytes(verySecureKey);算法.Key = keyArray;我在最后一行(64 位而不是 32 位)上遇到密钥违规 - 但这在 AS3Crypto 中工作正常。想法?
    猜你喜欢
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 2014-02-06
    • 2023-03-17
    • 2019-01-16
    相关资源
    最近更新 更多