我想使用 PKCS#7 作为一些加密、签名内容的容器格式,并且我们需要在 CBC 模式下使用 AES 和基于 ISO 10126 的填充。我似乎找不到用于此组合的算法标识符的具体参考。我可以发明自己的工具,但会失去与其他工具的互操作性。
嘿,我对加密和解密很陌生,说实话,甚至对 C# 语言也很陌生。基本上,我有一个 TCP 聊天服务器,可以“保存”日志并加密文本文件。这就是我加密的方式(基于 MSDN 示例):
public static void EncryptFile(string strInputFileName, string strOutputFileName, string strKey)
{
FileStream fsIn = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read);
FileStream fsOut = new FileStream(strOutputFileName, FileMode.Create, FileAccess.Write);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(strKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(strKey);
ICryptoTransform desencrypt = des.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(fsOut, desencrypt, CryptoStreamMode.Write);
byte[] byteArrayInput = new byte[fsIn.Length - 1];
fsIn.Read(byteArrayInput, 0, byteArrayInput.Length);
cryptostream.Write(byteArrayInput, 0, byteArrayInput.Length);
fsIn.Close();
fsOut.Close();
}
Run Code Online (Sandbox Code Playgroud)
该方法成功对文件进行完全加密。这是我的解密方法:
public static void DecryptFile(string strInputFileName, string strOutputFileName, string strKey)
{ …Run Code Online (Sandbox Code Playgroud) 我对 C 相当陌生,最近一直致力于制作一个简单的加密/解密程序。我设法很好地进行了加密,但在解密方面遇到了障碍。
相关代码如下:
加密(其中 asciinum 是字母的 ascii 值,k 是要移动的“vigenere”密钥)。
//shifts lowercase letters by key
if (asciinum >= 97 && asciinum <= 123)
{
f = p % keylen;
k = key[f];
asciinum = (asciinum - 97) + k;
asciinum = (asciinum % 26) + 97;
letterc = (char) asciinum;
//printf("%c\n", letterc);
cipher[j] = letterc;
p++;
}
//shifts uppercase letters by key
if (asciinum >= 65 && asciinum <= 91)
{
f = p % keylen;
k = key[f];
asciinum …Run Code Online (Sandbox Code Playgroud) 我想使用 RSA 来保护应用程序中的许可证文件。想法如下:
问题是我必须将私钥与我的应用程序一起发送。如果我对公钥保密会有问题吗?
如果没有,还有哪些其他好的(足够的)方案来创建许可证文件系统?
我想在 android 中使用 BouncyCastle 进行 GnuPG 加密(想要获取 .gpg 文件)。但我收到此错误。(不支持的类文件主要版本 59。
无法转换 bcprov-jdk15on-1.67.jar (org.bouncycastle:bcprov-jdk15on:1.67))
我的gradle版本是:gradle-6.7.1-bin.zip
JAVA_VERSION="1.8.0_242"
请帮忙。
或者,如果有人可以建议我使用其他方式在 android 中进行 GnuPG 加密,那也将非常有帮助。
我想加密和解密字符串。我为此使用了 Nodejs 加密。我读过在加密和解密时强烈建议使用 IV。我想将加密数据存储在 MySQL 数据库中,并在需要时对其进行解密。我知道解密过程也需要 IV。但究竟什么是 IV,我应该如何存储它?我读到一些关于 IV 不能保密的内容。这是否意味着我可以将它存储在它所属的加密数据旁边?
我在 python 中使用以下模块进行rsa加密。
https://github.com/sybrenstuvel/python-rsa
可以通过pip安装,如下pip3 install rsa
我已经阅读了在此处使用此模块的信息:https : //github.com/sybrenstuvel/python-rsa/blob/master/doc/usage.rst
我能够生成公钥和私钥,还能够使用以下代码使用公钥加密消息
import rsa
pubKey, priKey = rsa.newkeys(1024)
print("Public key: ",pubKey)
print("Private key: ",priKey)
msg = "vinay kumar shukla".encode('utf8')
print("Message without encryption:",msg)
msgEnc = rsa.encrypt(msg, pubKey)
print("encrypted message:",msgEnc)
Run Code Online (Sandbox Code Playgroud)
但我想将私钥存储到某个文件中,正如您可以在该模块的使用文件中读取的那样,他们提供了从.pem文件中读取密钥的方法,因此这意味着我也应该将密钥存储在pem文件中,但我是不知道如何将这个模块生成的密钥存储到文件中。
当我打印此模块生成的私钥时,它给了我以下输出
PrivateKey(8647494628885176696347621451257950700244697066080136004727560667550523829374958314554596272099668415472356485265099323795859891239567212729331504592847959, 65537, 80620400968137738399200401402545247384675983145016755403642821122013062179228267902734675759971390409853232911734749752372599473758015795215587460952985, 6068766834338315918835399238932380729501892761840591316766866213831546939444337723, 1424917922362067845458877023625137340152906787710542109910805914692739733)
Run Code Online (Sandbox Code Playgroud)
如果我创建一个文件key.pem并将此密钥存储到文件中,则存储此密钥。文件的内容是
-----BEGIN RSA PRIVATE KEY-----
PrivateKey(8647494628885176696347621451257950700244697066080136004727560667550523829374958314554596272099668415472356485265099323795859891239567212729331504592847959, 65537, 80620400968137738399200401402545247384675983145016755403642821122013062179228267902734675759971390409853232911734749752372599473758015795215587460952985, 6068766834338315918835399238932380729501892761840591316766866213831546939444337723, 1424917922362067845458877023625137340152906787710542109910805914692739733)
-----END RSA PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud)
当我尝试阅读它时,它给了我错误,例如padding error etc请告诉我如何存储这些密钥,然后将其读取以进行解密。
我正在使用 Golang 的加密包,特别是 crypto/aes,带有 32 字节的密钥(因此,AES-256)和 GCM 方法(Galois/Counter Mode)。
我从一个文件中读取了多个 16384 字节的块并生成了一个密码块、一个 GCM 方法和一个 12 字节的随机数。
然后,我将随机数添加到密文中,以便在解密时将它们拆分,以访问随机数(因为 12 字节的大小是已知的)。
人们会期望生成的密文是 16384 + 12 个字节 = 16396;但是,在实际加密时,我得到的大小为 16412 字节,因此添加了 16 字节。解密每个块后,我得到 16384 的“正常”大小。
这是一个快速示例。
block, _ := aes.NewCipher([]byte("W9FLKnyv397R82kKuFpfp6y8usGRf49a"))
gcm, _ := cipher.NewGCM(block)
nonce = make([]byte, gcm.nonceSize()) // nonceSize is 12 bytes
_, _ = io.ReadFull(rand.Reader, nonce) // populate nonce with random data
for {
src := make([]byte, 1024 * 16) // let's hypotise this src is a chunk of a file, …Run Code Online (Sandbox Code Playgroud) 到目前为止我的代码是:
public class TripleDES {
/**
* @param args the command line arguments
* @throws java.security.NoSuchAlgorithmException
* @throws javax.crypto.NoSuchPaddingException
* @throws java.security.InvalidKeyException
* @throws javax.crypto.IllegalBlockSizeException
* @throws javax.crypto.BadPaddingException
*/
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
//Encrypt: C = EK3(DK2(EK1(P)))
//Decrypt: P = DK3(EK2(DK1(C)))
Scanner sc = new Scanner(System.in);
//Generate key for DES
KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
SecretKey secretKey = keyGenerator.generateKey();
SecretKey secretKey2 = keyGenerator.generateKey();
SecretKey secretKey3 = keyGenerator.generateKey();
//Text Enc & Dec
Cipher cipher …Run Code Online (Sandbox Code Playgroud) 我创建了一个函数来将输入的字符串拆分为单词列表,然后将每个单词中的字母替换为其移位的对应物,但是当我将移位设置为超过 30 时,它的打印结果不变。
def ceaser_cipher_encoder(string , num):
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
new_string = ""
string_list = string.split(" ")
new_list = []
for word in string_list:
word1 = ""
for charecter in word:
letter_position = alphabet.index(charecter)
letter_position_with_shift = letter_position + num
if letter_position_with_shift > 25:
letter_position_with_shift = 0 + ((letter_position - 25) - 1)
word1 += charecter.replace(charecter, …Run Code Online (Sandbox Code Playgroud) encryption ×10
aes ×2
cryptography ×2
python ×2
rsa ×2
3des ×1
aes-gcm ×1
android ×1
bouncycastle ×1
c ×1
c# ×1
cryptostream ×1
des ×1
file ×1
gnupg ×1
go ×1
java ×1
kotlin ×1
node-crypto ×1
node.js ×1
nonce ×1
pkcs#7 ×1
standards ×1