我正在研究一些与内存中的秘密数据一起使用的应用程序.有没有办法确保在JVM终止时覆盖所有内存?在JVM终止后,任何秘密数据都不应留在内存中.
免责声明:据我所知,以下内容不适合在生产环境中提供"安全性".它简单地说比在我的系统上存储的敏感数据上使用XOR或rot13"好一点".
我将以下代码放在一起,以允许我对这些敏感值使用AES加密.AES需要16个字节的块; 所以我需要填充.我想将这些数据保存在文本文件中; 所以我添加了base64编码:
from __future__ import print_function
from Crypto.Cipher import AES
import base64
crypto = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s: s[0:-ord(s[-1])]
def scramble(data):
return base64.b64encode(crypto.encrypt(pad(data)))
def unscramble(data):
return unpad(crypto.decrypt(base64.b64decode(data)))
incoming = "abc"
print("in: {}".format(incoming))
scrambled = scramble(incoming)
print("scrambled: {}".format(scrambled))
andback= unscramble(scrambled)
print("reversed : {}".format(andback))
Run Code Online (Sandbox Code Playgroud)
对于python2; 打印:
in:abc
scrambled:asEkqlUDiqlUpW1lw09UlQ == …
服务器是RHEL7,Kerberos是AD(Windows).我只是KDC的客户.
Arcfour-hmac工作正常但是当我将加密类型更改为aes-256并设置新的keytab时,kinit仍然有效,但不是kvno.即使用户似乎拥有有效的票证(在klist中),他也无法再启动服务.
我无法访问Kerberos AD,但它似乎已正确配置为使用aes-256,因为最终用户(在Windows计算机上)已经请求此加密类型的票证.
我的krb5.conf:
[libdefaults]
default_realm = TOTO.NET
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
default_tkt_enctypes = aes256-cts aes128-cts des-cbc-md5 des-cbc-crc
default_tgs_enctypes = aes256-cts aes128-cts des-cbc-md5 des-cbc-crc
permitted_enctypes = aes256-cts aes128-cts des-cbc-md5 des-cbc-crc
[realms]
TOTO.NET = {
kdc = kdc1.toto.net
kdc = kdc2.toto.net
admin_server = kdc1.toto.net
}
[domain_realm]
.toto.net = TOTO.NET
toto.net = TOTO.NET
Run Code Online (Sandbox Code Playgroud)
这里是我尝试使用kvno获取票证时遇到的错误:
[2477332] 1493147723.961912: Getting credentials myuser@TOTO.NET -> nn/myserver@TOTO.NET using ccache FILE:/tmp/krb5cc_0
[2477332] 1493147723.962055: Retrieving myuser@TOTO.NET -> nn/myserver@TOTO.NET …Run Code Online (Sandbox Code Playgroud) 我正在使用此功能使用openssl AES 256 CBC加密数据:
int encryptAES(unsigned char *plaintext, int plaintext_len, unsigned char *key,
unsigned char *iv, unsigned char *ciphertext)
{
EVP_CIPHER_CTX *ctx;
int len;
int ciphertext_len;
/* Create and initialise the context */
if(!(ctx = EVP_CIPHER_CTX_new())) return handleErrors();
/* Initialise the encryption operation. IMPORTANT - ensure you use a key
* and IV size appropriate for your cipher
* In this example we are using 256 bit AES (i.e. a 256 bit key). The
* IV size for *most* modes …Run Code Online (Sandbox Code Playgroud) 我尝试使用加密来加密文件。这是我的代码:
const crypto = require('crypto');
const fs = require('fs');
const input = fs.createReadStream('test.jpg');
const output = fs.createWriteStream('test.enc');
const sharedSecret = crypto.randomBytes(256);
const initializationVector = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', sharedSecret, initializationVector);
input.pipe(cipher).pipe(output);
Run Code Online (Sandbox Code Playgroud)
我得到了错误:
crypto.js:191
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
^
Error: Invalid key length
at Error (native)
at new Cipheriv (crypto.js:191:16)
at Object.Cipheriv (crypto.js:189:12)
at Object.<anonymous> (/Users/lijinyao/Projects/HyperAlbum/Encryption/encrypt.js:10:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
Run Code Online (Sandbox Code Playgroud)
我虽然sharedSecret的长度应与aes-length相同,但事实并非如此。我应该使用多长?谢谢 :)
我正在使用Python 3.6上的PyCryptodome实现公钥加密.当我尝试创建对称加密密钥并加密/解密变量时,一切正常.但是,在我介绍RSA(和PKCS1_OAEP)的那一刻,它一切顺利 - session_key加密很好但是当我尝试解密它时,我收到以下错误:
Traceback (most recent call last):
File "enctest.py", line 109, in <module>
deckey = decrypt_val(enckey)
File "enctest.py", line 77, in decrypt_val
session_key = cipher.decrypt(ciphertext)
File "/usr/lib/python3.6/site-packages/Crypto/Cipher/PKCS1_OAEP.py", line 187, in decrypt
modBits = Crypto.Util.number.size(self._key.n)
AttributeError: 'bytes' object has no attribute 'n'
Run Code Online (Sandbox Code Playgroud)
我的代码如下.任何人都可以看看,告诉我我做错了什么?
from Crypto.Cipher import AES, PKCS1_OAEP
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Random import get_random_bytes
random_generator = Random.new().read
keys = RSA.generate(1024, random_generator)
pubkey = keys.publickey()
privkey = keys.exportKey()
pubcipher = PKCS1_OAEP.new(pubkey) # ciphertext …Run Code Online (Sandbox Code Playgroud) 您好我正在尝试在我的应用程序中实现加密.我使用角度(angular-4)作为前端,使用节点js作为后端.通过socket.io通过自定义命令完成通信.但基本上我坚持的是在客户端找到适当的RSA加密库.客户端将首先请求服务器获取RSA公钥.服务器用密钥响应,但现在我找不到任何适合使用此公钥使用RSA加密数据的库.我试过node-rsa.以下是代码sn
import * as NodeRSA from 'node-rsa';
@Injectable()
export class SecurityService {
RSA: any
initializeRSA(key: string) {
this.RSA = new NodeRSA();
this.RSA.importKey(key)
console.log(this.RSA.encrypt('Hello World'));
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误.
Error during encryption. Original error: TypeError: crypt.createHash is not a function
at NodeRSA.webpackJsonp.../../../../node-rsa/src/NodeRSA.js.module.exports.NodeRSA.$$encrypt
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助.
我试着找到答案,自己看这里并在别处搜索了一段时间,但我还是有一些问题.
假设这个Java代码:
try
{
int cipherMode = Cipher.ENCRYPT_MODE;
SecretKeySpec secretKey = ...; // generated previously using KeyGenerator
byte[] nonceAndCounter = new byte[16];
byte[] nonceBytes = ...; // generated previously using SecureRandom's nextBytes(8);
// use first 8 bytes as nonce
Arrays.fill(nonceAndCounter, (byte) 0);
System.arraycopy(nonceBytes, 0, nonceAndCounter, 0, 8);
IvParameterSpec ivSpec = new IvParameterSpec(nonceAndCounter);
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(cipherMode, secretKey, ivSpec);
File inFile = new File(...);
File outFile = new File(...);
long bytesRead = 0;
try (FileInputStream is = new FileInputStream(inFile);
FileOutputStream …Run Code Online (Sandbox Code Playgroud) 我试图在go中构建一个base64编码的sha1哈希,但我得到的结果与其他编程语言的结果非常不同
package main
import (
"crypto/sha1"
"encoding/base64"
"fmt"
)
func main() {
c := sha1.New()
input := []byte("hello")
myBytes := c.Sum(input)
fmt.Println(base64.StdEncoding.EncodeToString(base64.StdPadding))
}
Run Code Online (Sandbox Code Playgroud)
此Go Code打印出来 aGVsbG/aOaPuXmtLDTJVv++VYBiQr9gHCQ==
我的Python代码看起来像这样
import hashlib
import base64
print(base64.b64encode(hashlib.sha1('hello').digest()))
Run Code Online (Sandbox Code Playgroud)
和输出 qvTGHdzF6KLavt4PO0gs2a6pQ00=
我的用于比较的bash命令看起来像这样
echo -n hello| openssl dgst -sha1 -binary |base64
Run Code Online (Sandbox Code Playgroud)
输出这个 qvTGHdzF6KLavt4PO0gs2a6pQ00=
这让我假设python代码正在做一切正确的事情.但为什么要打印另一个结果.我的错误在哪里?
Thnx提前
报表服务器无法验证数据库中加密数据的完整性。(rsCannotValidateEncryptedData)。
无法还原加密密钥,因此我删除了密钥并尝试使用rskeymngt进行重新生成,但是没有运气。得到
报告服务器无法验证数据库中加密数据的完整性。(rsCannotValidateEncryptedData)'
访问http://localhost/ReportServer和运行时出现该错误rskeymgmt -s。
不知道下一步该怎么做。我有用户需要访问的报告。
encryption ×10
python ×3
aes ×2
java ×2
node.js ×2
openssl ×2
angular ×1
c ×1
cryptography ×1
frontend ×1
go ×1
jvm ×1
kerberos ×1
padding ×1
pycryptodome ×1
python-3.x ×1
rhel ×1
sha1 ×1
sql-server ×1