我想将像“Hello World”这样的消息转换为 base58,然后能够使用 node.js 对其进行解码。Base-58 模块有以下解释,但我无法完全理解如何转换我的消息。
Base58.encode(a Buffer or Uint8Array) returns a String
Base58.decode(a String) returns a Buffer
Run Code Online (Sandbox Code Playgroud)
我想我需要先将消息转换为其他内容,然后再转换为 Base58。要解码 Base58 消息,再次需要转换为其他内容,然后从那里转换为文本,对吧?
在很多地方,我看到 Java 代码使用 AES 和 PKCS#5 填充。我不明白这怎么可能行得通。
PKCS#5 填充旨在与块大小 <= 8 字节的密码一起使用。AES 的块大小为 16 字节。所有使用 AES 和 PKCS#5 的代码都是错误的吗?或者框架内部是否使用 PKCS#7 来代替?所讨论的框架是 Sun 提供的 Java、JCE 和 BouncyCastle。
这是例外情况:
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : DER input, Integer tag error
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(Unknown Source)
at java.security.KeyFactory.generatePrivate(Unknown Source)
Caused by: java.security.InvalidKeyException: IOException : DER input, Integer tag error at sun.security.pkcs.PKCS8Key.decode(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
这是代码:
import java.io.*;
import java.security.*;
import java.security.KeyStore.PasswordProtection;
import java.security.cert.CertificateException;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.util.encoders.Base64;
public class KeyPairUtil {
final static String keyStoreFile = "D:\\aeskey.jks";
private static final ASN1ObjectIdentifier AES = ASN1ObjectIdentifier.getInstance(NISTObjectIdentifiers.id_aes128_CBC);
public static void main(String[] args) throws Exception {
final …Run Code Online (Sandbox Code Playgroud) 从如何实现基于密码的加密来看,很明显我需要保存盐、IV 和密文以便稍后解密。
我以这种格式存储十六进制值
DatatypeConverter.printHexBinary(salt) + DatatypeConverter.printHexBinary(iv) + DatatypeConverter.printHexBinary(ciphertext);
我需要以二进制格式存储值吗?
DatatypeConverter.printBase64Binary(salt) + DatatypeConverter.printBase64Binary(iv) + DatatypeConverter.printBase64Binary(ciphertext));
输出清楚地表明盐、静脉注射结束的位置,这太糟糕了
lIvyAA/PZg4=fE4gTZUCPTrKQpUKo+Z1SA==4/gAdiOqyPOAzXR69i0wlC7YFn9/KOGitZqpOW2y3ms=
Run Code Online (Sandbox Code Playgroud)
以十六进制格式存储是否会导致数据丢失?
IV 的长度是恒定的吗?就我而言,它始终是 32 个字符(十六进制),或者我什至还需要存储 IV 的长度?因为盐长度最初固定为 8 位(16 个十六进制字符)
(我使用 PBKDF2WithHmacSHA1 算法进行密钥生成,使用 AES/CBC/PKCS5Padding 进行密码)
在 Chrome 中,这会失败:
window.crypto.subtle.generateKey(
{
name: "RSA-OAEP",
modulusLength: 4096,
hash: {name: "SHA-256"},
},
true,
["sign", "verify", "encrypt", "decrypt"]
)
Run Code Online (Sandbox Code Playgroud)
为什么这是不可能的?为什么我无法创建可用于加密和签名的密钥对?RSA 密钥本身没有此限制。
概述我正在尝试做的事情。我有需要读入 pandas 的文件的加密版本。由于多种原因,解密到流而不是文件要好得多,所以这是我下面的兴趣,尽管我也尝试解密到文件只是作为中间步骤(但这也不起作用)。
我可以让它适用于 csv,但不适用于 hdf 或 stata(我接受适用于 hdf 或 stata 的答案,尽管两者的答案可能相同,这就是为什么我合并为一个问题)。
加密/解密文件的代码取自另一个stackoverflow问题(我目前找不到)。
import pandas as pd
import io
from Crypto import Random
from Crypto.Cipher import AES
def pad(s):
return s + b"\0" * (AES.block_size - len(s) % AES.block_size)
def encrypt(message, key, key_size=256):
message = pad(message)
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CBC, iv)
return iv + cipher.encrypt(message)
def decrypt(ciphertext, key):
iv = ciphertext[:AES.block_size]
cipher = AES.new(key, AES.MODE_CBC, iv)
plaintext = cipher.decrypt(ciphertext[AES.block_size:])
return plaintext.rstrip(b"\0")
def encrypt_file(file_name, key):
with open(file_name, 'rb') …Run Code Online (Sandbox Code Playgroud) 我们可以使用spiped或stunnel在数据传输时保护数据的安全。但是当数据处于静止状态时我们如何做到这一点呢?如果有人拿走了整个数据库怎么办?我们如何加密持久数据存储?我们需要在应用层做这个吗?
我想“手动”将消息的摘要/散列与该摘要上解密的签名值进行比较。
为此,我想使用属于最初签署摘要的私钥的公钥来解密消息的签名值(签名摘要)。
我有以下物品:
我对如何使用 openssl 实现这一目标感到困惑。
我正在尝试对此处和此处描述的命令进行变体,但是我有点迷失了。
我想我应该使用以下方法将签名从 base64 值转换为八位字节:
base64 --d sigfile > sigfile_octet?
然后我使用命令:
openssl rsautl -inkey pubkey.pem -pubin -in sigfile_octet
这会给我解密的八位字节签名值吗?为了将其与 Base64 摘要进行比较,我需要执行哪些后续步骤?
ps 我已经使用Aleksey 的 XML 安全库验证了签名,所以我知道摘要应该与解密的签名值匹配。
非常感谢您的帮助!
亲切的问候,
迪德里克
encryption command-line openssl digital-signature public-key
我有一个Xamarin.iOS应用程序,它使用Akavache缓存数据并减少不必要的服务器请求数据的数量.一切都像预期的那样运作得很好BlobCache.LocalMachine,喜欢它.
现在我想确保加密后的数据处于静止状态.从在线研究和阅读文档,我发现默认实现并没有实际加密iOS上的缓存,我实际上需要提供自定义实现IEncryptionProvider.
我跟着这篇文章:http://kent-boogaart.com/blog/password-protected-encryption-provider-for-akavache
添加了此线程的输入:https://github.com/akavache/Akavache/issues/190
结束了这个实现:
public interface IPasswordProtectedEncryptionProvider : IEncryptionProvider
{
void SetPassword(string password);
}
public sealed class MyEncryptionProvider : IPasswordProtectedEncryptionProvider
{
static readonly byte[] salt = Encoding.ASCII.GetBytes("dVBZMQWyFRcJOIas");
readonly IScheduler scheduler;
readonly SymmetricAlgorithm symmetricAlgorithm;
ICryptoTransform decryptTransform;
ICryptoTransform encryptTransform;
public MyEncryptionProvider()
{
scheduler = BlobCache.TaskpoolScheduler ?? throw new ArgumentNullException(nameof(scheduler), "Scheduler instance is null");
symmetricAlgorithm = new RijndaelManaged();
var securePassword = "kadhaskdhsakhaskjdhaskjdhaskdjashdkjahkfghkjhew";
SetPassword(securePassword);
}
public void SetPassword(string password)
{
if(password == null) …Run Code Online (Sandbox Code Playgroud) 我有java项目,我想将它与SonarCloud集成我遵循官方步骤:
使用SonarQube扫描仪检查代码#
在检查代码之前,您需要:
- 在SonarCloud上为您的帐户创建用户身份验证令牌.
- 加密此令牌travis加密abcdef0123456789或在存储库设置中定义SONAR_TOKEN
- 找到您想要推送项目的SonarCloud.io组织并获取其密钥
- 为您的项目创建一个sonar-project.properties文件(请参阅文档).然后将以下行添加到.travis.yml文件以触发分析:
在我的travis.yml文件中添加
addons:
sonarcloud:
organization: "xelian-github"
token:
secure: ${SONAR_TOKEN}
branches:
- master
script:
# other script steps might be done before running the actual analysis
- sonar-scanner
Run Code Online (Sandbox Code Playgroud)
其中SONAR_TOKEN是Travis CI上的变量,指向SonarCloud的密钥.(它未加密).
从SonarCloud我添加权限

但是当我开始travis构建时,我有以下错误:
Setting environment variables from repository settings
$ export SONAR_TOKEN=[secure]
....
ERROR: Error during SonarQube Scanner execution
ERROR: You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator.
ERROR:
ERROR: Re-run …Run Code Online (Sandbox Code Playgroud) encryption ×10
java ×4
aes ×2
rsa ×2
akavache ×1
bouncycastle ×1
byte ×1
command-line ×1
cryptography ×1
database ×1
decode ×1
encode ×1
hex ×1
ios ×1
javascript ×1
jce ×1
node.js ×1
openssl ×1
pandas ×1
public-key ×1
python ×1
python-3.x ×1
redis ×1
sonarcloud ×1
sonarqube ×1
travis-ci ×1
xamarin.ios ×1