再会!我有几个关于使用 Signal 协议的问题。
我有一个小型的基本聊天,想要加密消息(端到端)。正如您所见,我想尝试 Signal,但我想保留我的服务器端实现。
从我所看到的 - 所有的工作都是从创建公钥并将它们发送到服务器开始的。然后,当 Alice 想给 Bob 写一条消息时,她要求服务器向她发送一个 PreKeyBundle。之后所有的消息交换就像在 github repo 的 SessionBuilderTest 中一样。
主要问题是:
我有一个带日志记录的python脚本。现在我想使用 pycrypto 使用 AES 加密日志。
import logging
import base64
from Crypto.Cipher import AES
aes = AES.new(cryptoKey)
logging.basicConfig(filename='example.log',level=logging.DEBUG) # file name, not custom file
logging.info('text')
Run Code Online (Sandbox Code Playgroud)
我想base64.b64encode(aes.encrypt('#logging text#'))在将其写入 log 之前使用。什么是最有效的方式来做到这一点?
我正在使用 IDataProtector 来保护和取消保护控制器内没有问题。我可以注射保护剂并使用它。
IDataProtector _protector;
public HomeController(IDataProtectionProvider provider)
{
_protector = provider.CreateProtector(GetType().FullName);
}
public IActionResult Index()
{
Test test = new Test();
test.originaltext = "1";
test.encryptedtext = _protector.Protect(test.originaltext);
test.originaltext = _protector.Unprotect(test.encryptedtext);
return View(test);
}
Run Code Online (Sandbox Code Playgroud)
这然后显示了加密和解密的“1”
然后我可以创建一个链接并将其传递给同一控制器上的另一个操作
<a asp-controller="Home"
asp-action="GetKey"
asp-route-id="@Model.encryptedtext">
Pass Key to getkey
</a>
Run Code Online (Sandbox Code Playgroud)
这会传递加密数据并允许我在 GetKey 操作中解密。
public IActionResult GetKey(String id)
{
Test test = new Test();
test.encryptedtext = id;
test.originaltext = _protector.Unprotect(id);
return View(test);
}
Run Code Online (Sandbox Code Playgroud)
如果我然后尝试创建一个链接并将其传递给另一个控制器。
<a asp-controller="Key"
asp-action="GetKeyController"
asp-route-id="@Model.encryptedtext">
Pass Key to other controller
</a>
Run Code Online (Sandbox Code Playgroud)
它因错误而失败
System.Security.Cryptography.CryptographicException: …Run Code Online (Sandbox Code Playgroud) 我浏览了MongoDB 文档,这些文档解释了如何配置仅在 MongoDB Enterprise 中可用的加密。
如何在MongoDB Community Edition v3.4 中实现静态数据?
我正在尝试编写一个简单的 Java 程序,该程序将使用AES-256-CBC. 有课:
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AesCBC {
private byte[] key;
private byte[] iv;
private static final String ALGORITHM="AES";
public AesCBC(byte[] key, byte[] iv) {
this.key = key;
this.iv = iv;
}
public byte[] encrypt(byte[] plainText) throws Exception{
SecretKeySpec secretKey=new SecretKeySpec(key,ALGORITHM);
IvParameterSpec ivParameterSpec=new IvParameterSpec(iv);
Cipher cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE,secretKey,ivParameterSpec);
return cipher.doFinal(plainText);
}
public byte[] getKey() {
return key;
}
public void setKey(byte[] key) {
this.key = key;
}
public byte[] getIv() {
return iv; …Run Code Online (Sandbox Code Playgroud) 昨天我阅读了问题Algorithm to create costum Template/Code from String。因为这个问题没有很好地表达出来,所以它立刻就被否决了。然而,我认为这个问题本身并没有那么糟糕,所以我决定再次提出这个问题的更好版本。
好的,我想知道新 Spotify 代码的字符串加密是如何工作的。见下图:

我对在 javascript 中实现这种模式加密的可能性的程度非常感兴趣。
Spotify 代码 -我已经在上面提到过-排列成一行,分为不同大小的条。
因此,假设有一行被分为 24 个条形,并且所有条形的大小都可以是“3”、“5”、“7”或“9”。
string = 'hello' --> pattern = '3,3,5,7,9,3,7,9,9,3,3,5,3,9,5,3,3,7,5,9,3,9,3,9'
Run Code Online (Sandbox Code Playgroud)
什么是将字符串(比如 5 个字符)转换为独特模式的好方法/简单方法,然后也可以转换回来并作为字符串读取?
这是我迄今为止开发的代码,但在此代码中,我使用了一个包含 10 种不同可能性(--> 条大小)的键数组,但我只喜欢我们 4 种不同的大小。
解释:
我将我的字符串 'hello' 转换为二进制格式,并将该字符串分成最多 3 个的组以获得如下内容:['001', '110', '0']。
之后我使用上面的结果数组并在下面的键数组中找到匹配项并获取索引(10 种不同的索引 --> 10 种不同的可能性)并将它们用作条形大小。
但是,必须有一种更有效的方法将字符串转换为独特的模式。我希望有人可以帮助我改进我的小算法。预先感谢一百万。
string = 'hello' --> pattern = '3,3,5,7,9,3,7,9,9,3,3,5,3,9,5,3,3,7,5,9,3,9,3,9'
Run Code Online (Sandbox Code Playgroud)
最近我用作曲家做了一个新项目,并用 make:auth 添加了非常基本的身份验证 - 没什么特别的。
接下来我想加密我的数据库中的name和email列,所以我将它们的类型从 VARCHAR(191) 更改为 LONGTEXT 并向用户模型添加了一些非常基本的修改器
public function setNameAttribute($value) {
$this->attributes['name'] = Crypt::encryptString($value);
}
public function getNameAttribute($value) {
return Crypt::decryptString($value);
}
public function setEmailAttribute($value) {
$this->attributes['email'] = Crypt::encryptString($value);
}
public function getEmailAttribute($value) {
return Crypt::decryptString($value);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用我的非常简单的路线进行测试时,即使我在错误内容中看到字段已被正确解密,我也会收到有效载荷无效错误。
Route::get('user',function(){
$user= \App\User::find(3);
//dd($user->name);
dd(Crypt::decryptString($user->name));
dd(Crypt::decryptString($user->email));
Run Code Online (Sandbox Code Playgroud)
});
我正在使用 Python 3 中的 Pycryptodome 开发加密程序。我正在尝试加密(字节)字符串,然后对其进行解密并验证 MAC 标签。当我验证它时,会抛出一个错误。
这是代码:
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
aes_key = get_random_bytes(24)
aes_cipher = AES.new(aes_key, AES.MODE_GCM)
encrypted, MACtag = aes_cipher.encrypt_and_digest(b"A random thirty two byte string.")
# Imagine this is happening somewhere else
new_aes_cipher = AES.new(aes_key, AES.MODE_GCM, nonce=aes_cipher.nonce)
new_aes_cipher.verify(MACtag)
decrypted = new_aes_cipher.decrypt(encrypted)
Run Code Online (Sandbox Code Playgroud)
这是错误:
Traceback (most recent call last):
File "aespractice.py", line 10, in <module>
new_aes_cipher.verify(tag)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/Crypto/Cipher/_mode_gcm.py", line 441, in verify
raise ValueError("MAC check failed")
ValueError: MAC check failed
Run Code Online (Sandbox Code Playgroud)
我查看了文档,在我看来一切都很好。为什么你认为这个程序会这样?任何帮助,将不胜感激。
我在 Kotlin 中创建了这两个扩展来加密/解密字符串:
fun String.encrypt(seed : String): String {
val keyGenerator = KeyGenerator.getInstance("AES")
val secureRandom = SecureRandom.getInstance("SHA1PRNG")
secureRandom.setSeed(seed.toByteArray())
keyGenerator.init(128, secureRandom)
val skey = keyGenerator.generateKey()
val rawKey : ByteArray = skey.encoded
val skeySpec = SecretKeySpec(rawKey, "AES")
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
cipher.init(Cipher.ENCRYPT_MODE, skeySpec)
val byteArray = cipher.doFinal(this.toByteArray())
return byteArray.toString()
}
fun String.decrypt(seed : String): String {
val keyGenerator = KeyGenerator.getInstance("AES")
val secureRandom = SecureRandom.getInstance("SHA1PRNG")
secureRandom.setSeed(seed.toByteArray())
keyGenerator.init(128, secureRandom)
val skey = keyGenerator.generateKey()
val rawKey : ByteArray = skey.encoded
val skeySpec = SecretKeySpec(rawKey, "AES") …Run Code Online (Sandbox Code Playgroud) 我有在 Angular 上加密数据的代码,但我不知道如何在服务器端解密
var panno = CryptoJS.AES.encrypt("FEAPS8905Q", "myPassword").toString();
Run Code Online (Sandbox Code Playgroud)
U2FsdGVkX19mi5mXlJ14Lj0XcJBbqMPDzi/UeNXK4Cw=以角度加密,在使用 Http.post 方法发送加密后,我没有得到确切的数据,而是得到????????????????
我也在C# 上使用了这个参考Decrypting,但我得到了一些数据,比如 ????????????????
public string Decrypt(string cipherText)
{
string EncryptionKey = "myPassword";
cipherText = cipherText.Replace(" ", "+");
byte[] cipherBytes = Convert.FromBase64String(cipherText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] {
0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.Padding = PaddingMode.None;
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new …Run Code Online (Sandbox Code Playgroud) encryption ×10
cryptography ×3
aes ×2
c# ×2
java ×2
python ×2
algorithm ×1
angular ×1
arrays ×1
asp.net-core ×1
cryptojs ×1
javascript ×1
kotlin ×1
laravel ×1
logging ×1
mongodb ×1
mutators ×1
node.js ×1
payload ×1
php ×1
pycrypto ×1
pycryptodome ×1
python-2.7 ×1
security ×1
string ×1