标签: encryption

从PHP的物理内存中清除变量的值

一般的问题是:在PHP中取消设置String变量的值之后,是否可以从物理内存中删除该变量的值?

该问题是由安全标准的某些要求引起的(在处理某些重要数据时,应该没有办法将数据从内存转储到磁盘)。根据“ 内存是否已加密? ”主题,没有好的方法可以对内存中的数据进行加密。

因此,在PHP中取消设置String变量时,您不能肯定地说内存中的数据已被覆盖。关于为变量设置新值的相同故事。

因此,我是否有可能在不更改unset方法核心代码的情况下从内存中清除变量值?

php memory encryption

5
推荐指数
2
解决办法
1289
查看次数

X.509 DN的所有部分都是可选的吗?

X.509中DN的所有部分都是可选的吗?
来自RFC3280:

必须准备本规范的实现,以便在发行者和主题(第4.1.2.6节)名称中接收以下标准属性类型:

  * country,
  * organization,
  * organizational-unit,
  * distinguished name qualifier,
  * state or province name,
  * common name (e.g., "Susan Housley"), and
  * serial number.
Run Code Online (Sandbox Code Playgroud)

我找不到这些是否是强制性的.
我问,因为我看到一个由受信任的CA签署但在发行人的字段CN中丢失的证书(C但我不认为这很重要).
我当时希望这CN是强制性的.是吗?
遗漏CN发行人的领域是否有任何安全隐患?

security encryption ssl x509certificate x509

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

避免加密和编码的URL字符串中的换行符

我试图实现一个简单的字符串编码器来混淆URL字符串的某些部分(以防止它们被用户弄乱).我使用的代码几乎与JCA指南中的示例相同,除了:

  • 使用DES(假设它比AES快一点,并且需要更小的密钥)和
  • Base64 en /解码字符串以确保它对URL保持安全.

由于我无法理解的原因,输出字符串以换行符结束,我认为这不会起作用.我无法弄清楚造成这种情况的原因.关于类似的东西的建议更容易或指向其他一些资源阅读?我发现所有的密码学参考都超过了我的头脑(并且过度杀伤),但是简单的ROT13实现将无法工作,因为我想处理更大的字符集(并且不想浪费时间实现可能的东西)与我没想到的晦涩字符有问题).

样本输入(无换行符):

http://maps.google.com/maps?q=kansas&hl=en&sll=42.358431,-71.059773&sspn=0.415552,0.718918&hnear=Kansas&t=m&z=7
Run Code Online (Sandbox Code Playgroud)

示例输出(换行符如下所示):

GstikIiULcJSGEU2NWNTpyucSWUFENptYk4m5lD8RJl8l1CuspiuXiE9a07fUEAGM/tC7h0Vzus+
jAH6cT4Wtz2RUlBdGf8WtQxVDKZVOzKwi84eQh2kZT9T3KomlnPOu2owJ/2RAEvG+QuGem5UGw==
Run Code Online (Sandbox Code Playgroud)

我的编码片段:

final Key key = new SecretKeySpec(seed.getBytes(), "DES");
final Cipher c = Cipher.getInstance("DES");
c.init(Cipher.ENCRYPT_MODE, key);
final byte[] encVal = c.doFinal(s.getBytes());
return new BASE64Encoder().encode(encVal);
Run Code Online (Sandbox Code Playgroud)

java encryption

5
推荐指数
2
解决办法
1万
查看次数

Postgres 和 Node 之间的加密/解密

问题:我们必须加密某个表(Postgres)上的某个列。它必须在 SQL 查询和我们的 Nodejs/sequelize 应用程序层中可解密。加密可以发生在任一层中,但必须可以从任一层中解码。

\n\n

我遇到的问题(我确信这是用户错误)是,如果我在数据库中加密,我只能在数据库中解密,对于节点也是如此。

\n\n

我尝试过在 postgres 和node中使用PGP_SYM_ENCRYPTand 。我已经得到它的解密没有错误,但返回乱码。ENCRYPTcryptocrypto-js/aes

\n\n

到目前为止我尝试过的一些事情(测试键是thirtytwocharsthirtytwocharsplus):

\n\n
set() {\n  this.setDataValue('field', seq.cast(seq.fn('PGP_SYM_ENCRYPT', val, \n  config.AES_KEY), 'text'))\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这正确地写入了字段,使得 PGP_SYM_DECRYPT 能够解密它,但是(显然?)没有办法告诉 Sequelize 用函数调用包装字段名称,所以我觉得有很多额外的 js 是可以避免的

\n\n
const decipher = crypto.createDecipher('aes256', config.AES_KEY)\ndecipher.setAutoPadding(false);\nreturn decipher.update(new Buffer(this.getDataValue('field', 'binary'), 'binary', 'ascii')) + decipher.final('ascii')\n
Run Code Online (Sandbox Code Playgroud)\n\n

这将解码该字段,但返回乱码 ( \xef\xbf\xbdMq\xef\xbf\xbd\xef\xbf\xbd8Ya\xef\xbf\xbdb) 而不是值 ( test)

\n\n
aes.encrypt('test', config.AES_KEY)\naes.decrypt(field, config.AES_KEY).toString(CryptoJS.enc.Utf8)\n
Run Code Online (Sandbox Code Playgroud)\n\n

这可以很好地加密,解密也很好,但是 Postgres 在尝试解密时会出错(使用 或PGP_SYM_DECRYPT)DECRYPT。将结果字段转换::TEXT并粘贴到在线 AES …

encryption postgresql aes node.js

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

如何在 pycryptodom 中使用 ECC 加密消息

我正在使用混合加密(RSA+AES),但长度很大,现在我想使用 ECC 而不是 RSA,但在 pycryptodom 中没有实现。这是我的 RSA 代码

def generate_keys():
    key = RSA.generate(1024)
    private_key = key.exportKey(format='PEM', pkcs=8, 
                  protection="scryptAndAES128-CBC")
    f = open("private_key.pem", "wb")
    f.write(private_key)
    public_key = key.publickey().exportKey('PEM')
    f = open("public_key.pem", "wb")
    f.write(public_key)
    f.close()

def encrypt(username, msg):
    #get the reciever's public key
    f = open("{}.pem".format(username)) # a.salama.pem
    recipient_key = RSA.import_key(f.read())
    f.close()

    # Encrypt the session key with the reciever's public RSA key
    cipher_rsa = PKCS1_OAEP.new(recipient_key)

    # Encrypt the data with the AES session key
    session_key = get_random_bytes(16)

    cipher_aes = AES.new(session_key, AES.MODE_EAX)
    ciphertext, …
Run Code Online (Sandbox Code Playgroud)

python encryption pycrypto

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

如何在springboot中使用自定义类加载器

如何在 Spring Boot 中使用自定义类加载器加载 bean

\n\n

我需要加密 Spring Boot 项目。

\n\n

起初我尝试使用proguard,但失败了,因为 spring 使用大量 Annotations 并且它有DI。

\n\n

然后我尝试使用自定义类加载器。我想先加密我的类文件,然后使用我的自定义类加载器加载加密的类文件,然后解密它\xe3\x80\x82

\n\n

这是我的演示: https: //github.com/CaiBaohong/boot-by-custom-loader

\n\n

启动时失败:

\n\n
ConfigServletWebServerApplicationContext : \n  Exception encountered during context initialization - cancelling refresh attempt: \n    org.springframework.beans.factory.UnsatisfiedDependencyException: \n      Error creating bean with name \'methodValidationPostProcessor\' defined in class path resource \n        [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: \n          Unsatisfied dependency expressed through method \'methodValidationPostProcessor\' parameter 0; \n          nested exception is \n            org.springframework.beans.factory.CannotLoadBeanClassException: \n              Error loading class [com.abc.bootbycustomloader.controller.UserController] \n …
Run Code Online (Sandbox Code Playgroud)

encryption obfuscation spring classloader spring-boot

5
推荐指数
0
解决办法
3266
查看次数

如何在nodejs中加密和解密字符串/对象

我想加密一个对象然后解密它。加密效果很好,但解密失败。下面是我的代码:

加密扩展.js

const crypto = require("crypto")
const password = "shared_key"
const algorithm = "aes256"

export const encrypt = (text) => {
    if(!text) return ''
    const cipher = crypto.createCipher(algorithm, password);
    let crypted = cipher.update(text, 'utf-8', 'base64');
    crypted += cipher.final('base64');
    return crypted;
}

export const decrypt = (text) => {
    if(!text) return ''
    const decipher = crypto.createDecipher(algorithm, password);
    let decrypted = decipher.update(text, 'base64', 'utf-8');
    decrypted += decipher.final('utf-8');
    return decrypted;
}
Run Code Online (Sandbox Code Playgroud)

在我的test.js中,我有:

import {encrypt, decrypt} from './crypto_ext.js'
let test = {key1: …
Run Code Online (Sandbox Code Playgroud)

encryption node.js cryptojs node-crypto

5
推荐指数
1
解决办法
2万
查看次数

在此沙箱演示中使用 Libsodium.js 进行简单的 Javascript 加密

我花了令人尴尬的几个小时试图让 Libsodium.js 工作。

请参阅我的小提琴演示(以及下面粘贴的代码)。

我不断得到Error: wrong secret key for the given ciphertext。

我更喜欢将这个PHP 示例function simpleEncrypt($message, $key)复制到 Libsodium.js 中。

但作为一个初学者,我什至很高兴从 Libsodium.js 存储库中获取基本示例来工作。

有什么提示吗?


这是代码(也显示在工作小提琴中):

const _sodium = require("libsodium-wrappers");
const concatTypedArray = require("concat-typed-array");
(async () => {
    await _sodium.ready;
    const sodium = _sodium;
    const utf8 = "utf-8";
    const td = new TextDecoder(utf8);
    const te = new TextEncoder(utf8);
    const nonceBytes = sodium.crypto_secretbox_NONCEBYTES;
    const macBytes = sodium.crypto_secretbox_MACBYTES;

    let key = sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed");

    function encrypt_and_prepend_nonce(message, key) …
Run Code Online (Sandbox Code Playgroud)

javascript encryption encryption-symmetric libsodium

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

python中的AES-GCM解密

我正在尝试解密 AES_GCM 生成的密文。密文是从 golang 中的“crypto/aes”库生成的。现在,我正在尝试使用 cryptodome 库解密 python 中的加密文本。

func AESEncryption(key []byte, plaintext []byte)([]byte, error){
   c, err := aes.NewCipher(key)
   if err != nil {
      log.Printf("Error ocurred in generating AES key %s", err)
      return nil,  err
   }

   gcm, err := cipher.NewGCM(c)
   if err != nil {
      return nil,  err
   }

  nonce := make([]byte, gcm.NonceSize())
  if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
    log.Printf("Error ocurred in generating AES key %s", err)
      return nil, err
  }

  return gcm.Seal(nonce, nonce, plaintext, nil), …
Run Code Online (Sandbox Code Playgroud)

python encryption go

5
推荐指数
1
解决办法
2万
查看次数

混淆存储在源代码中的解密密钥

我想随我的软件一起发送一个文件,其内容需要对我的软件用户隐藏(无法进行在线身份验证,因为该软件需要离线执行)。我执行此操作的方法是使用 AES-256 加密文件,然后将加密密钥存储在源文件中。但事实证明,从编译的可执行文件中恢复这个密钥非常容易,因为整个字符串只是位于一个连续的块中。以下 Python 代码查找密钥:

with open("/path/to/executable", 'rb') as readfile:
    content = readfile.read()

to_find = 'C0SH3VKNTKR4CRGH0R8WXD9WR5I1GS'  # example key

for i in range(len(content) - len(to_find)):
substr = content[i:i + len(to_find)]
if substr == to_find:
    print "Found at index %d" % i
Run Code Online (Sandbox Code Playgroud)

当然,作为攻击者,我不知道我在寻找什么。但是,通过查看可执行文件所依赖的共享库(这些库是开源的,解密文件的格式也是一种广泛使用的标准),人们可以轻松推断出解密文件所需的格式。因此基本上,人们可以在构成可执行文件的二进制内容上滑动一个 30 个字符的长窗口,使用每个字符串解密文件,然后检查是否可以正确解析它。

我知道,如果密钥以某种格式存在于源代码中,则不可能完全保护密钥,但是在这种情况下,有哪些典型技术可用于使攻击者的日子变得更加艰难?

我想到的明显解决方案是将密钥拆分为多个子字符串并将它们分散在整个代码中,或者在字符串中间插入虚拟字符,但我对软件安全性的了解为零,所以很高兴听到其他建议。

security encryption obfuscation

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