标签: encryption

了解 Rfc2898DeriveBytes 的工作原理

我正在为数据库中的敏感数据编写加密序列。

目前,我正在根据 UserId 获取 GUID,并将其通过哈希处理。然后,我通过 Rfc2898DeriveBytes 运行哈希来获取 Key 和 IV,然后使用 Rijndael 函数对数据进行加密。

我的代码如下所示:

        var salt = new byte[] { 1, 2, 23, 234, 37, 48, 134, 63, 248, 4 };
        const int iterations = 1000;
        using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(GenerateHash("2525"), salt, iterations)) {
            _key = rfc2898DeriveBytes.GetBytes(32);
            _iv = rfc2898DeriveBytes.GetBytes(16);
        }
Run Code Online (Sandbox Code Playgroud)

然后,我传递 _key 和 _iv 来解密或加密数据。我的目标是让每个用户在每个会话中始终可以访问他们的唯一密钥。话虽如此,什么可以被随机化并且仍然保持这个功能呢?我是否总是必须使用相同的盐和相同的 IV 来获取我想要的数据?

c# encryption

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

共享和存储 IV 以进行 AES 加密/解密

我目前在 Android 应用程序上对用户密码使用 AES-ECB 加密,但我必须将此应用程序的数据库连接到一个网站,用户可以在该网站上以与移动应用程序相同的方式注册和登录。

我读到 ECB 模式不安全,所以我想通过生成 IV 来使用 CBC。

在服务器端的 php 和应用程序中将 IV 作为常量存储在代码中(我也以这种方式存储密钥)是否安全?

如果没有,网站和移动应用程序是否有办法共享其 IV 来加密/解密用户密码?

或者,我可能选择了错误的加密算法,可能有一种更适合我的需求

php encryption android aes

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

MachineKey.Protect 和 MachineKey.Unprotect

我使用 .net 4.5 和 MachineKey.Protect/MachineKey.Unprotect 来加密和解密值。我想知道当我们将代码部署到拥有多个服务器的生产环境时,MachineKey.Protect/MachineKey.Unprotect 是否可以在不同步计算机密钥的情况下正常工作?

这是解密的示例代码:

var bytes = Convert.FromBase64String(Token);
var decryValue = MachineKey.Unprotect(bytes, Purpose);
string plainText = Encoding.UTF8.GetString(decryValue);
Run Code Online (Sandbox Code Playgroud)

让我知道你的想法!

c# encryption asp.net-mvc-4 .net-4.5

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

md5 加密来自 str(input) 的密码

我试图从文件中哈希密码,然后将其与用户给出的密码进行匹配。并不是超级安全,只是足够安全,以便密码在文件中不是纯文本。我收到错误

TypeError: Unicode-objects must be encoded before hashing
Run Code Online (Sandbox Code Playgroud)

如果我输入 hashpass = hashlib.md5(b'p').hexdigest() 它会起作用,但它只加密“p”

我如何让它加密我的字符串输入?

程序

import hashlib

status = ""

def passhash():    
    code = open("password.txt", "r")
    password = code.readline()                
    global encrypt
    encrypt = hashlib.md5(password).hexdigest()

def checkPassword():
    for key in range(3):        
        p = input("Enter the password >>")      
        hashpass = hashlib.md5(p).hexdigest()

        if hashpass == encrypt:            
            print("password correct!")
            status = "q"
            return status
        else:
            print ('wrong password, try again')
    print ('you have failed')

def Main():
    status = input("p for program, q to quit: …
Run Code Online (Sandbox Code Playgroud)

python authentication encryption passwords md5

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

SHA-256 可以解密吗?

我正在参加之前的信息安全考试。

我正在研究与密码加密有关的加盐。我的问题是 - 如果 SHA 256 是一种单向加密,那么如何解密?

我只是想,当通过电子邮件发送消息时,它们会被加密和解密,以便可以访问消息或文件。

SHA 256 如何工作?如果加密无法解密,您如何查看您的消息或文件?或者它只是保护密码本身?

我目前正在研究这个(在大学),希望得到任何帮助。请原谅我的问题中的任何愚蠢错误,因为我仍在尝试了解这个主题。

谢谢。

encryption cryptography

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

智能卡中的身份验证密钥

我使用JCManager工具在我的 java 卡上加载小程序。该软件在顶部有三个身份验证密钥字段,名为S_ENC、S_MAC和DEK。

据我所知,ENC代表Encryption,MAC代表Message Authentication Code,DEK代表Data Encryption Key。

我想知道他们何时使用(通信的哪一步?初始更新、外部身份验证?...)?

每次通信中都使用这三个密钥,还是其中一些密钥可以选择使用?

哪里?(卡或终端或两者兼而有之?)

另外,我想知道什么是KEK?KEK智能卡里有吗?

encryption cryptography smartcard javacard smartcard-reader

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

Java 解密创建附加符号

我写的加解密代码如下

import java.io.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.BadPaddingException;
import java.nio.file.Files;
import java.util.Scanner;

public class EncryptFile
{
    public static void main(String args[]) throws IOException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException {
//Encrypt Mode
        FileOutputStream outputStream = new FileOutputStream(new File("D:\\encryptedNewStringFile.txt"));
        Key secretKey = new SecretKeySpec("encKey".getBytes(), "Blowfish");
        Cipher cipher = Cipher.getInstance("Blowfish");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] getFileBytes = "writing a file using encryption ".getBytes();
        byte[] outputBytes = cipher.doFinal(getFileBytes);
        outputStream.write(outputBytes);
        getFileBytes …
Run Code Online (Sandbox Code Playgroud)

java encryption blowfish

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

如何在 Java 14 中销毁 SecretKey?

我试图Secretkey在解密后清除我的。从我读过的内容来看,SecretKeys可以通过destroy自 Java 8 以来的方法销毁。我使用的是 Java 14,所以它应该是可能的。

但是,每当我在键上使用 destroy 方法时,DestroyFailedException都会抛出 a 。我还看到人们在他们的代码中忽略了该异常,但是,如果我这样做,我可以在调用destroy方法后打印密钥。

这是我的解密方法:

private byte[] decrypt(byte[] encryptedText, char[] password) throws InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException, DestroyFailedException {

    ByteBuffer bb = ByteBuffer.wrap(encryptedText);

    byte[] iv = new byte[ivLengthByte];
    bb.get(iv);

    byte[] salt = new byte[saltLengthByte];
    bb.get(salt);

    byte[] cipherText = new byte[bb.remaining()];
    bb.get(cipherText);

    SecretKey key;
    key = crypto.getAESKeyFromPassword(password, salt);

    Cipher cipher;
    cipher = Cipher.getInstance(algorithm);

    cipher.init(Cipher.DECRYPT_MODE, key, new GCMParameterSpec(tagLengthBit, iv));

    byte[] plainText = cipher.doFinal(cipherText); …
Run Code Online (Sandbox Code Playgroud)

java encryption destroy secret-key aes-gcm

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

在 UTF-8 中加密 Golang 中的字符串以放入 postgres

我在 go 中使用 crypto 来获取密码并使用密码短语来加密密码,然后将其作为字符串存储在 postgres sql 数据库中。加密工作正常,但是当我尝试将它添加到我的数据库时,我收到一个错误,似乎表明从 []byte 到 string 类型混淆了加密密码。

func Encrypt(password string, passphrase string) string {
    data := []byte(password)
    block, _ := aes.NewCipher([]byte(createHash(passphrase)))
    gcm, err := cipher.NewGCM(block)
    if err != nil {
        panic(err.Error())
    }
    nonce := make([]byte, gcm.NonceSize())
    if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
        panic(err.Error())
    }
    ciphertext := gcm.Seal(nonce, nonce, data, nil)
    return string(ciphertext)
}

func createHash(key string) string {
    hasher := md5.New()
    hasher.Write([]byte(key))
    return hex.EncodeToString(hasher.Sum(nil))
}
Run Code Online (Sandbox Code Playgroud)

当我运行此代码并尝试在数据库中添加行时,出现错误

ERROR #22021 invalid byte sequence …
Run Code Online (Sandbox Code Playgroud)

encryption postgresql utf-8 go

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

安装加密依赖后出现颤振错误

我正在开发一个简单的应用程序,在身份验证方面,我需要使用 encrypt 包来加密 jwt 令牌,但是由于我安装了 encrypt 依赖项,flutter 现在给了我这个错误:

    flutter pub add encrypt Launching lib\main.dart on Chrome in debug mode...
    flutter/.pub-cache/hosted/pub.dartlang.org/pointycastle-3.1.3/lib/key_derivators/argon2.dart:42:27:
Error: The integer literal 0xFFFFFFFFFFFFFFFF can't be represented exactly in JavaScript.
    Try changing the literal to something that can be represented in Javascript.
    In Javascript 0x10000000000000000 is the nearest value that can be represented exactly. static const int M32L = 0xFFFFFFFFFFFFFFFF; 
    
    flutter/.pub-cache/hosted/pub.dartlang.org/pointycastle-3.1.3/lib/src/utils.dart:313:9:
Error: The integer literal 0xFFFFFFFFFFFFFFFF can't be represented exactly in JavaScript.
    Try changing the literal to something that …
Run Code Online (Sandbox Code Playgroud)

encryption web dart flutter argon2-ffi

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