标签: encryption

BCrypt 检查是否已经加密?

我的问题是如何检查密码是否已经用 Bcrypt 加密。如果是,让 Bcrypt 什么都不做,只需保留密码。我正在使用 Java(EE),Spring。

public static String hashPassword(String userPassword) {
    String bCrypt = null;
    if (userPassword == null)
        throw new NullPointerException("Input password for hashing was null.");
    bCrypt = BCrypt.hashpw(userPassword, BCrypt.gensalt(12));
    return bCrypt;
}
Run Code Online (Sandbox Code Playgroud)

java encryption spring cryptography bcrypt

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

RSA 加密 - 如何加密到小于密钥的大小

我在我的项目中使用 RSA 加密,我需要将字节数组加密为加密字节数组,他的长度小于密钥长度(我使用 2048 位密钥)。当我在 c# 中使用 RSACryptoServiceProvider 类时,它总是将它加密为一个字节数组,他的长度是密钥长度(256 个字节)。我知道我不能将它加密成比密钥更长的大小,但是,我可以将它加密成更小的一个(原始未加密的字节长度数组)吗?

.net c# encryption cryptography rsa

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

System.Security.Cryptography.CryptographicException:RSACryptoserviceProvider 中的长度错误

我想RSACryptoServiceProvider在 wp8 项目中使用c#加密和解密数据。我正在创建非对称密钥:

CspParameters parameters = new CspParameters();
parameters.KeyContainerName = "MyContainer";

RSACryptoServiceProvider provider = new RSACryptoServiceProvider(parameters);  
Run Code Online (Sandbox Code Playgroud)

现在我想加密数据。我在做:

CspParameters parameters = new CspParameters();

parameters.KeyContainerName = "MyContainer";
RSACryptoServiceProvider obj = new RSACryptoServiceProvider(parameters);
byte[] a = Generic.RSAEncrypt(ByteConverter.GetBytes(s[0]),
                              obj.ExportParameters(false), false); 

public static byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo,
                                bool DoOAEPPadding)
{
    try {
        byte[] encryptedData;
        //Create a new instance of RSACryptoServiceProvider. 
        CspParameters parameters = new CspParameters();
        parameters.KeyContainerName = "TCSContainer";
        using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(parameters))
        {
            //Import the RSA Key information. This only …
Run Code Online (Sandbox Code Playgroud)

c# encryption rsa windows-phone-8

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

加密中的密钥使用错误

这个类加密数据值,首先我得到密码如下,

KeyStore primaryKeyStore = getKeyStore(keyStoreFile, password, keyType, provider);
java.security.cert.Certificate certs = primaryKeyStore.getCertificate(aliasName);
cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, certs);
Run Code Online (Sandbox Code Playgroud)

但是上面代码的最后一行给出了以下错误。错误的密钥用法是什么意思?我不能将此证书用于加密目的吗?是否有单独的加密证书?

Caused by: java.security.InvalidKeyException: Wrong key usage 
at javax.crypto.Cipher.init(Cipher.java:1640) 
at javax.crypto.Cipher.init(Cipher.java:1549) 
at my.test.ciphertool.CipherTool.initCipher(CipherTool.java:167) 
... 1 more 
Run Code Online (Sandbox Code Playgroud)

java security encryption certificate

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

字符串到数字然后返回到 JavaScript 中的字符串加密/解密

我有一个形式为的字符串

[{"name":John, "title":'sir'\"SubTitle":'\gh}]
Run Code Online (Sandbox Code Playgroud)

它包含上面提到的所有字符,还有一些更像 . 等。是否有任何有效的算法/函数可以将此字符串转换为包含数字的数字字符串,例如 '34234354536564756756765745463543243' 并且它还可以将此数字字符串解码回原始字符串?

javascript string encryption

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

ECDiffieHellmanCng 实现和机制

我一直在阅读不同的密码算法,我遇到了“Diffie Hellman Cryptography Next Generation”。我对该算法进行了大量搜索,我发现它是一种非对称加密系统,在某些方面可以与 RSA 相媲美。我查看了 .Net System.Security.Cryptography,我发现它也提供了 Diffie-Hellman 密码学。所以我没有去MSDN,在那里我找到了一个关于如何在 C# 中使用它的很好的例子,但是这个例子给我带来了一些问题。让我先复制部分代码:(我不发布完整代码,因为我的问题主要是关于这部分)

public static byte[] alicePublicKey;

public static void Main(string[] args)
{
    using (ECDiffieHellmanCng alice = new ECDiffieHellmanCng())
    {

        alice.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
        alice.HashAlgorithm = CngAlgorithm.Sha256;
        alicePublicKey = alice.PublicKey.ToByteArray();
        Bob bob = new Bob();
        CngKey k = CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob);
        byte[] aliceKey = alice.DeriveKeyMaterial(CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob));
        byte[] encryptedMessage = null;
        byte[] iv = null;
        Send(aliceKey, "Secret message", out encryptedMessage, out iv);
        bob.Receive(encryptedMessage, iv);
    }

}

private static void Send(byte[] …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography public-key-encryption

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

Java AES 不解密阿拉伯语

我正在 Eclipse 上加密和解密字符串。我正在使用以下功能:

private final static String ALGORITHM = "AES";


    public static String cipher(String secretKey, String data) throws Exception {



        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

        KeySpec spec = new PBEKeySpec(secretKey.toCharArray(), secretKey.getBytes(), 128, 256);

        SecretKey tmp = factory.generateSecret(spec);

        SecretKey key = new SecretKeySpec(tmp.getEncoded(), ALGORITHM);



        Cipher cipher = Cipher.getInstance(ALGORITHM);

        cipher.init(Cipher.ENCRYPT_MODE, key);



        return toHex(cipher.doFinal(data.getBytes()));

    }


    public static String decipher(String secretKey, String data) throws Exception {



        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

        KeySpec spec = new PBEKeySpec(secretKey.toCharArray(), secretKey.getBytes(), 128, 256);

        SecretKey tmp = factory.generateSecret(spec);

        SecretKey key = …
Run Code Online (Sandbox Code Playgroud)

java eclipse encryption aes

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

Android android.credentials.UNLOCK 在没有密码的情况下初始化密钥库

有一个随机密钥来通过 AES 加密本地凭据,我正在按照以下教程尝试安全地存储该密钥,然后能够在以后解密:

nelenkov.blogspot.co.uk 在 android 中存储应用程序机密

本教程解释了如何访问系统密钥库并将密码存储在其中。

我面临的问题集中在调用UNLOCK ( android.credentials.UNLOCK ) KeyStore 上。未初始化 KeyStore 的设备(目前 API 低于 14),它们会显示一个对话框,要求输入 8 位密码。

本教程运行良好,但是显示此对话框甚至只显示一次,它会打扰大多数用户。

有什么办法可以跳过这个对话框吗?

如果有人描述了一种在本地保留密钥的更好方法,我会更高兴。

encryption android credentials aes android-keystore

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

org.apache.ws.security.WSSecurityException:一般安全错误(未找到用于解密的证书 (KeyId))

我继承了一些 WSS4J 安全网络服务的代码。它基于这个流行的教程:http : //distributedsenses.blogspot.com/2008/09/configuring-cxf-for-web-service.html

现在服务器端正在与其他客户端一起工作,但我的不是。:(

我为 tomcat 生成了一个密钥库,导出了公钥,并将其安装在服务器上。但是当我尝试调用时,服务器回复错误没有找到用于解密的证书(KeyId)

现在我没有对代码进行一些更改,但是我确实更改了包名称(我认为这对 SOAP 调用无关紧要)——我没有更改名称空间。

我什至在服务器上导出了证书,以确保我正确导入了它,并且它与客户端上的公钥完全匹配。所以我知道服务器有我的证书。

这是我的 OutInterceptor

 <bean 
   class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"
    id="TimestampSignEncrypt_Request">
    <constructor-arg>
        <map>
            <entry key="action" value="Timestamp Signature Encrypt"/>
            <entry key="user" value="clientwin"/>
            <entry key="encryptionUser" value="tomcat2"/>
            <entry key="signatureKeyIdentifier" value="DirectReference"/>
            <entry key="signaturePropFile" value="clientSign.properties"/>
            <entry key="encryptionPropFile" value="clientEncrypt.properties"/>
            <entry key="passwordCallbackClass" value="ClientKeystorePasswordCallback"/>
            <entry key="signatureParts" value="{Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body"/>
            <entry key="encryptionParts" value="{Element}{http://www.w3.org/2000/09/xmldsig#}Signature;{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body"/>
            <entry key="encryptionSymAlgorithm" value="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
            <entry key="encryptionKeyTransportAlgorithm" value="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
            <entry key="signatureAlgorithm" value="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
        </map>
    </constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)

还有我的 clientSign.properties

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=changeit
org.apache.ws.security.crypto.merlin.keystore.alias=clientwin
org.apache.ws.security.crypto.merlin.file=C:\\apache-tomcat-7.0.55\\ssl\\.keystore
Run Code Online (Sandbox Code Playgroud)

我收到此错误的任何原因。我知道我的公钥在服务器的信任库中。这适用于其他客户。知道我做错了什么吗?

java security encryption web-services wss4j

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

pgp_sym_encrypt 并解密 postgresql 中的整个列

我想用 aes 256 加密加密我的 postgreSQL 数据库中的 area_code 列。这是发生的事情.. 我能够轻松地加密它,但我无法解密它。

这是工作正常的加密查询:

update mytable t1 set area_code = t2.area_code from (select pgp_sym_encrypt(area_code,'Password', 'compress-algo=1, cipher-algo=aes256') as area_code,area_name from mytable) t2 where t1.area_name = t2.area_name;
Run Code Online (Sandbox Code Playgroud)

但是,如果我给出类似的内容,解密查询似乎不起作用

update mytable t1 set area_code = t2.area_code from (select pgp_sym_decrypt(area_code,'Password') as area_code,area_name from mytable) t2 where t1.area_name = t2.area_name;
Run Code Online (Sandbox Code Playgroud)

甚至当我尝试查看解密的 area_code 时

select pgp_sym_decrypt((select area_code from ci), 'Password') ;
Run Code Online (Sandbox Code Playgroud)

唯一有效的是当我使用单个记录并直接输入加密文本作为输入时。

select pgp_sym_decrypt('aes.encrypted.string.given.as.input', 'Password') ;
Run Code Online (Sandbox Code Playgroud)

sql encryption postgresql pgcrypto

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