标签: encryption

AES 算法中的密钥是公开的还是私有的?

这可能不是问这个问题的正确地方,但实际上我在互联网上看了很多东西来找到这个答案,但我找不到。我只想知道 AES 中的密钥是公开的还是私有的?先感谢您!

encryption cryptography aes

1
推荐指数
1
解决办法
537
查看次数

使用 TripleDES 加密时将初始化向量 (IV) 附加到加密字节

我想向客户端提供加密令牌,并且我使用 javax.crypto.Cipher 进行加密。根据我的阅读,不建议将 ECB 作为加密模式,因此我使用带有初始化向量的 CBC 和 TripleDES 作为密码方法。据我了解,有几点是正确的。

  1. 更重要的是,IV 是随机的,并且每次加密都会初始化一个新的,而不是保密。
  2. 必须使用相同的 IV 来加密和解密令牌。
  3. 没有存储 IV 值的标准方法,每个实现在这方面可能有所不同。

因此,对于这些情况,我通过存储附加到加密字节数组的 IV 来实现我的实现,并且在解密阶段,IV 从字节数组中切出并用于解密。以下是 Scala 代码,但在 Java 中不会有太大差异。

val algorithmName = "TripleDES"
def encrypt(bytes: Array[Byte], secret: String): Array[Byte] = {
  val secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), algorithmName)
  val encipher = Cipher.getInstance(algorithmName + "/CBC/PKCS5Padding")
  val iv = encipher.getParameters.getParameterSpec(classOf[IvParameterSpec])
  encipher.init(Cipher.ENCRYPT_MODE, secretKey, iv)
  encipher.doFinal(bytes) ++ iv.getIV
}

def decrypt(bytes: Array[Byte], secret: String): Array[Byte] = {
  val secretKey = new SecretKeySpec(secret.getBytes("UTF-8"), algorithmName)
  val encipher = Cipher.getInstance(algorithmName + "/CBC/PKCS5Padding") …
Run Code Online (Sandbox Code Playgroud)

java security encryption scala initialization-vector

1
推荐指数
1
解决办法
2246
查看次数

如何将 ssl 密码添加到 nginx 中的 ssl_ciphers

我正在使用 Let's Encrypt 在我的服务器中安装免费的 TLS/SSL 证书。我按照Mozilla SSL 配置生成器的建议并像这样配置了 nginx:

ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
Run Code Online (Sandbox Code Playgroud)

问题是我需要 Java 7 才能与服务器通信,但它不适用于上述配置。

当我将我的网站提交给ssllabs 时,我收到以下消息:

Java 7u25   Server sent fatal alert: handshake_failure
Run Code Online (Sandbox Code Playgroud)

如果我只是在 nginx 配置中评论 ssl_ciphers 行,那么与 Java 7 的通信就会开始工作。

# After commenting the line below it works
# ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
Run Code Online (Sandbox Code Playgroud)

所以我从ssllabs收到以下消息:

Java 7u25   RSA 2048 (SHA256)   TLS 1.0 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
Run Code Online (Sandbox Code Playgroud)

我不想让 ssl_ciphers 行注释,因为 nginx 将使用其默认配置,这不太安全。

我只想将密码 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 添加到 ssl_ciphers 列表中。

是否可以?怎么做?

encryption ssl nginx lets-encrypt

1
推荐指数
1
解决办法
4403
查看次数

将 ElGamal 加密从加密数字转换为字符串

我有以下 ElGamal 加密方案

const forge = require('node-forge');
const bigInt = require("big-integer");

// Generates private and public keys
function keyPairGeneration(p, q, g) {
    var secretKey = bigInt.randBetween(2, q.minus(2));
    var publicKey = g.modPow(secretKey, p);
    const keys = {
        secret: secretKey,
        public: publicKey
    }
    return keys;
}

// Generates a proxy and a user key
function generateProxyKeys(secretKey) {
    const firstKey = bigInt.randBetween(1, secretKey);
    const secondKey = secretKey.minus(firstKey);
    const keys = {
        firstKey: firstKey,
        secondKey: secondKey
    }
    return keys;
}

// Re-encrypts 
function preEncrypt(p, …
Run Code Online (Sandbox Code Playgroud)

string encryption encoding node.js elgamal

1
推荐指数
1
解决办法
682
查看次数

ASP.NET Core MVC 加密/解密 QueryString 值

我正在使用 ASP.NET Core 2.0 MVC、C#、Entity Framework Core Code First 和 SQL Server 2016。

我创建了一个 Web 表单,我所有的 CRUD 操作都运行良好。但是,我需要一些关于加密/解密传递给确认、编辑和删除视图的查询字符串值的帮助。

在我的“索引”页面上,当用户将鼠标悬停在指向这些操作方法的“编辑”和“删除”链接上时,我还想对 EmployeeID 进行加密。我不希望它们在索引页上可见。

请参阅我下面的代码。

楷模

public class Employee
{
    public int EmployeeID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public int DepartmentID { get; set; }
    public Department Department { get; set; }

    public int AppointmentID { get; set; }
    public Appointment Appointment { get; set; }
}

public class Department …
Run Code Online (Sandbox Code Playgroud)

c# encryption asp.net-core-mvc asp.net-core-2.0 asp.net-core-mvc-2.0

1
推荐指数
1
解决办法
1万
查看次数

如何在rails中加密和解密ID?

我有一个要求,用户应该登录,并且应该登陆特定页面。

基本上用户会在他的电子邮件中获得一个链接,点击该链接后,用户将登录系统并进入特定页面。目前我正在使用记录 ID(用户 ID)实现此功能。

网址看起来像这样。

localhost:3000/details?user_id=412

def details
  @user = User.find(user_id)
  signin(@user)
end
Run Code Online (Sandbox Code Playgroud)

由于上述网址,任何人都可以通过更改 ID 随机访问其他用户帐户。我希望这个 id 在 url 中加密,并且在控制器操作中我想解密它。我不希望在整个应用程序中进行这种加密,我只想为此操作实现。

例如:

localhost:3000/details?user_id=SnrIcaMA8rikrnNX6RRKNw

def details
  @user = User.find(decrypt(user_id))
  signin(@user)
end
Run Code Online (Sandbox Code Playgroud)

encryption ruby-on-rails

1
推荐指数
1
解决办法
1883
查看次数

JavaScript WebCrypto importKey 错误:AES 密钥数据必须为 128 或 256 位

我正在尝试导入现有的密钥,但无论我做什么,我都会得到:“AES 密钥数据必须是 128 位或 256 位”

我有一个从 0 到 255 的 128 个 int ArrayBuffer,即使我用 Uint8Array 包装它也不起作用。即使是新的 Uint8Array(128) 也会返回相同的错误。

crypto.subtle.importKey("raw", new Uint8Array(128), { name: "AES-CBC" }, true, ["encrypt", "decrypt"]).then(cryptoKey => {
            console.log(cryptoKey);

        }).catch(err => {
            console.log(err);
            });
Run Code Online (Sandbox Code Playgroud)

javascript encryption cryptography aes webcrypto-api

1
推荐指数
1
解决办法
1437
查看次数

sha256_crypt.encrypt 总是返回另一个哈希

我正在使用python和flask开发一个webapp。它有一个用户系统,当然还有一个注册表。我正在使用 passlib.hash.sha256 来加密想要注册的用户的密码。这是我在做什么:

from passlib.hash import sha256_crypt as sha256
[...]
if request.method == "POST" and form.validate():
    username = request.form['username']
    password = request.form['password']
    confirm_password = request.form['confirm_password'] 
    email = request.form['email']

    password = sha256.encrypt(password) #Encryption.



    c, conn = connection('accounts') #Connection to the database


    x = c.execute("SELECT * FROM accounts  WHERE username = '%s' OR email = '%s'" %(thwart(username), thwart(email)))

    if x:
        flash("We are very sorry, but this Username/Email-address is already taken. Please try again")
    else:
        c.execute('INSERT INTO accounts VALUES ("%s", "%s", "%s")' %(thwart(username), …
Run Code Online (Sandbox Code Playgroud)

python encryption sha256

1
推荐指数
1
解决办法
2260
查看次数

错误:指定的密钥不是此算法的有效大小

我坚持使用加密方法。我对加密或字节数组的了解不多,所以我很难解决这个问题。

这是我的代码:

 public static class EncryptDecrypt {
    private static byte[] key = { };
    private static string sEncryptionKey = "B@|@j!";
    private static byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};

public static string Encrypt(string stringToEncrypt)
    {
        string returnstring = "";
        try
        {

            key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey);
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms,
                des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            returnstring = Convert.ToBase64String(ms.ToArray());

            //URL Encryption Avoid Reserved Characters …
Run Code Online (Sandbox Code Playgroud)

c# encryption algorithm

1
推荐指数
1
解决办法
6140
查看次数

CBC - 密文窃取解密

该图显示了带有密文窃取的 CBC-,(b) 是块长度。输出密文是 c1,...,c4 这个图的解密如何?我希望有人可以用图表向我解释它,因为我在维基百科中查看了解释,这让我感到困惑。 在此处输入图片说明

encryption cryptography cbc-mode

1
推荐指数
1
解决办法
835
查看次数