标签: encryption

如何在Ruby中使用PKI(公钥/私钥)加密?

我想加密一个字符串,以便最终用户可以验证它是由我加密的,但是他们不能自己加密它.

例如,我有一个私钥'private',一个公钥'public',一个消息'hello world',并且想要做类似的事情:

private_key = 'private'
public_key = 'public'
message = 'hello world'

encrypted_value = Crypto.encrypt(message, private_key)
# encrypted_value is now 'd92a01df241a3'

is_verified = Crypto.verify(message, public_key)
# given just the public key and the message, is_verified will 
# be able to tell whether it's accurate

# note that the encrypted_value cannot be generated by just the public_key
# but it can be verified by the public_key
Run Code Online (Sandbox Code Playgroud)

ruby encryption ssl cryptography pki

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

AES-CTR在Go中加密并在CryptoJS中解密

我在使用CryptoJS解密使用Go lang加密的文本时遇到问题.

这是Go代码:https: //play.golang.org/p/xCbl48T_iN

package main

import (
    "crypto/aes"
    "crypto/cipher"
    "encoding/base64"
    "fmt"
)

func main() {
    key := []byte("1234567890123456")
    plaintext := []byte("text can be a random lenght")

    block, err := aes.NewCipher(key)
    if err != nil {
        panic(err)
    }

    // The IV needs to be unique, but not secure. Therefore it's common to
    // include it at the beginning of the ciphertext.
    // BTW (only for test purpose) I don't include it

    ciphertext := make([]byte, len(plaintext))

    iv := []byte{'\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f','\x0f'} …
Run Code Online (Sandbox Code Playgroud)

javascript encryption cryptography go cryptojs

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

用于加密/解密时处理更改密码的最佳方法

问题:

我需要加密/解密大量数据.使用密码(更具体地使用RNCrytor lib)对该数据进行加密/解密.一个人应该能够更改此密码.

我的问题是如何最有效地完成这项工作?

我不是那么好的解决方案:

除了循环遍历所有数据并对其进行解密之外,必须有更好的方法.然后使用新密码再次加密它.

encryption passwords cryptography change-password swift

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

加密实施 - 令人困惑的结果

我正在尝试对我的项目使用简单的加密/解密(treyfer),但是没有可用的解密参考实现.我得到的(基于维基百科的实现)是:

uint8_t rotl(uint8_t x) {
  return (x << 1) | (x >> 7);
}

uint8_t rotr(uint8_t x) {
  return (x >> 1) | (x << 7);
}

void encrypt (uint8_t text[8], uint8_t key[8]) {
  int r, i;
  uint8_t t;

  for (r=0; r<NUMROUNDS; r++) {
      text[8] = text[0];
      for (i=0; i<8; i++) {
          text[i+1] = rotl((text[i+1] + sbox[(key[i] + text[i]) % 256]));
      }
      text[0] = text[8];
  }
}

void decrypt (uint8_t text[8], uint8_t key[8]) {
    int r, i;
    uint8_t t;

    for …
Run Code Online (Sandbox Code Playgroud)

c encryption cryptography

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

在Android中存储AES密钥

我想在预装M设备上将AES密钥存储在AndroidKeyStore中

我试图使用生成的密钥 KeyGenerator

KeyGenerator keyGen = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES);
keyGen.init(256);
SecretKey secretKey = keyGen.generateKey();
Run Code Online (Sandbox Code Playgroud)

但我无法从KeyStore访问该密钥,后来我尝试使用 KeyPairGenerator

KeyPairGenerator kpg = KeyPairGenerator.getInstance(
                KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
kpg.initialize(new KeyPairGeneratorSpec.Builder(this)
                .setAlias("alias")
                .build());
KeyPair kp = kpg.genKeyPair();
Run Code Online (Sandbox Code Playgroud)

但

java.security.NoSuchAlgorithmException:未找到KeyPairGenerator AES实现

encryption android keystore android-keystore

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

Java将00010打印为8

解决这个问题的解密程序我用Java编写.这是有问题的代码

public static int int_to_int(int input)
{
    int[] value_array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
            11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
            21, 22, 23, 24, 25, 26};
    int[]bin_array= {00000, 00001, 00010, 00011,
            00100, 00101, 00110, 00111,
            01000, 01001, 01010, 01011, 01100,
            01101, 01110,  01111, 10000, 10001,
            10010,  10011, 10100, 10101, 10110,
            10111, 11000,11001, 11010, 11011};
    for(int i=0; i <27; i++)
    {
        System.out.println("hello");
        if(input==value_array[i])
        {
            System.out.println("returning: " + bin_array[i] + "at: …
Run Code Online (Sandbox Code Playgroud)

java encryption byte bits

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

如何在数据库中存储CryptoJS加密密码

我对CRYPTO JS加密的东西很陌生,我想将加密的哈希存储在数据库中(我想存储在Firebase数据库中)。

    var hash = CryptoJS.AES.encrypt('my message', 'secret key 123');
Run Code Online (Sandbox Code Playgroud)

我正在尝试将哈希变量存储在数据库中。但是,当我尝试存储时,它向我显示错误,它是功能,无法存储。

PS-我正在尝试将加密的哈希存储在数据库中,并想从数据库中调用应用程序另一页上的加密哈希并在那里解密。

那可能吗?如果是,那么请告诉我如何。谢谢

javascript encryption hash firebase cryptojs

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

(java.security.InvalidKeyException)当cipher.init(Cipher.DECRYPT_MODE,key)出现一个预期错误时,未设置IV

SecretKey key = keyFactory.generateSecret(keySpec);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] ciphertext = cipher.doFinal(cleartext);

return bytes2String(ciphertext);
Run Code Online (Sandbox Code Playgroud)

我正在获取java.security.InvalidKeyException,即,当cipher.init(Cipher.DECRYPT_MODE,key).cleartext出现一个预期错误时,没有设置IV,这是基于base64解码字符串的字节数组。我在这里缺少什么?

java encryption

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

带有Web请求的javascript加密

我们有一个有趣的问题.我们的客户想要使用我们基于Web的应用程序(后端/ DB与我们合作).但是,他们希望加密患者信息,因此我们公司的任何人都无法看到它.会有一些javascript解决方案吗?或者某种方式在发送给我们之前使用他们的加密?

javascript encryption

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

如何将十六进制字符串转换回它的“ SecureRandom.random_bytes”二进制文件?

在Ruby中,我可以创建一个16字节的二进制文件并将其转换为十六进制字符串:

key     = SecureRandom.random_bytes(16)                    # => "hN\xDB\xAD\xAF\xB3R\xC0`\xB19\x1D\x19.\xD3I"
hex_key = key.each_byte.map { |byte| '%02x' % byte }.join  # => "684edbadafb352c060b1391d192ed349"
Run Code Online (Sandbox Code Playgroud)

在PHP和Javascript中,我可以将十六进制字符串转换回它的16字节二进制文件。

PHP:

<?php
hex2bin("684edbadafb352c060b1391d192ed349");
?>
Run Code Online (Sandbox Code Playgroud)

通过CryptoJS的 Javascript :

CryptoJS.enc.Hex.parse("684edbadafb352c060b1391d192ed349");
Run Code Online (Sandbox Code Playgroud)

但是,如何使用Ruby将十六进制字符串转换回16字节二进制文件呢?

ruby encryption binary hex

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