标签: encryption

Java:在数据加密过程中是否有任何编码器不包含正斜杠?

我需要以这样的URL传递加密格式的数据, http://localhost:8080/app/{encrypted_data}

那么,是否有编码器中不包含正斜杠(/)的编码器?

请注意:我不想手动从编码数据中用另一个字符替换'/'.

.................................................. .................................................. ..........

编辑:Oleg Estekhin评论使用Base64 URL安全编码工作正常,我只是在这里添加一个例子.

示例:编码:

String str = "subjects?_d=1";
byte[] bytesEncoded = Base64.encodeBase64URLSafe((str.getBytes()));
Run Code Online (Sandbox Code Playgroud)

解码:

Base64 decoder = new Base64(true);
byte[] decodedBytes = decoder.decode(new String(bytesEncoded));
System.out.println(new String(decodedBytes));
Run Code Online (Sandbox Code Playgroud)

输出:

c3ViamVjdHM_X2Q9MQ
subjects?_d=1
Run Code Online (Sandbox Code Playgroud)

java encryption encoding

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

何时以及为什么在使用BouncyCastle时使用ArmoredOutputStream装饰OutputStream

我对BouncyCastle和pgp很新.我在互联网上看过很多文章和样本.几乎每个加密样本都包含下面剪切的代码

if (armor) 
        out = new ArmoredOutputStream(out);
Run Code Online (Sandbox Code Playgroud)

似乎我的本地测试通过了护甲和无护甲.我用google搜索但发现很少有用,而ArmoredOutputStream的javadoc只显示这是基本的输出流.

那么有什么区别以及何时使用它?

完整的代码示例:

public static void encryptFile(String decryptedFilePath,
        String encryptedFilePath,
        String encKeyPath,
        boolean armor,
        boolean withIntegrityCheck)            
        throws Exception{

    OutputStream out = new FileOutputStream(encryptedFilePath);
    FileInputStream pubKey = new FileInputStream(encKeyPath);
    PGPPublicKey encKey = readPublicKeyFromCollection2(pubKey);
    Security.addProvider(new BouncyCastleProvider());

    if (armor) 
        out = new ArmoredOutputStream(out);

    // Init encrypted data generator
    PGPEncryptedDataGenerator encryptedDataGenerator =
            new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, withIntegrityCheck, new SecureRandom(),"BC");

    encryptedDataGenerator.addMethod(encKey);


    OutputStream encryptedOut = encryptedDataGenerator.open(out, new byte[BUFFER_SIZE]);

    // Init compression  
    PGPCompressedDataGenerator compressedDataGenerator = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
    OutputStream compressedOut = compressedDataGenerator.open(encryptedOut);  

    PGPLiteralDataGenerator …
Run Code Online (Sandbox Code Playgroud)

java encryption bouncycastle pgp openpgp

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

使用AES/CBC/NoPadding算法解密字符串

我想AES/CBC/Nopadding在c#Windows Phone 8应用程序中解密加密Sting .我的字符串在IsolatedSorage.我粘贴了垃圾桶HERE.

从这篇文章我使用AesManaged类来解密.但是如何设置填充,NoPadding因为默认情况下填充设置为PKCS7从这里开始.

        string fileName = "titlepage.xhtml";

        if (fileStorage.FileExists(fileName))
        {
            IsolatedStorageFileStream someStream = fileStorage.OpenFile(fileName, System.IO.FileMode.Open, FileAccess.Read);
            using (StreamReader reader = new StreamReader(someStream))
            {
                str1 = reader.ReadToEnd();

                MessageBox.Show(str1);

                try
                {
                    string text = Decrypt(str1, "****************", "****************");

                    MessageBox.Show(text);
                }
                catch (CryptographicException cryptEx)
                {
                    MessageBox.Show(cryptEx.Message, "Encryption Error", MessageBoxButton.OK);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "General Error", MessageBoxButton.OK);
                }
            }
        }

    public string Decrypt(string dataToDecrypt, string password, …
Run Code Online (Sandbox Code Playgroud)

c# encryption aes visual-studio-2012 windows-phone-8

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

基于Key和Initial Vector在SQL Server中创建对称AES128密钥

我有一些Key和Initial Vector,我在.NET应用程序中用于加密.让我们说它们是:

Key = 0x0102030405060708090A0B0C0D0E
IV  = 0xA1A2A3A4A5A6A7A8A9AAABACADAE
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我想在SQL Server上执行加密(不在应用程序中),但在应用程序中解密数据.我以为我可以在数据库中创建临时对称密钥并执行加密:

CREATE SYMMETRIC KEY #TempKey
    WITH ALGORITHM   = AES_128
    , IDENTITY_VALUE = ???
    , KEY_SOURCE     = ???
    ENCRYPTION BY PASSWORD = 'Pa$$w0rd';

OPEN SYMMETRIC KEY #TempKey
    DECRYPTION BY PASSWORD = 'Pa$$w0rd';

SELECT EncryptByKey(Key_Guid('#TempKey'), 'Secret Data');

CLOSE SYMMETRIC KEY #TempKey;
DROP SYMMETRIC KEY #TempKey;
Run Code Online (Sandbox Code Playgroud)

但我不知道我应该提供什么作为IDENTITY_VALUE和KEY_SOURCE在DB和我的应用程序之间有一个"共享"键.



更新2014-07-07

我想提供一些问题的背景知识.

  1. 首先,我正在使用EF Code First方法,当我需要执行一些数据库更新时,我使用Code First Migrations,我想进一步使用这种基于纯迁移的方法.不幸的是,正如在EF Code First迁移中使用自定义逻辑的问题中找到的那样,无法在Up或Down方法中获取当前的SqlConnection和SqlTransaction .我唯一的方法 - 使用Sql方法执行自定义SQL查询.

  2. 在下一个数据库更新中,我想要在一列中加密数据.加密应该满足两个条件:(1)数据应该在客户端应用程序中解密(不在SQL Server端),(2)对称密钥应该以加密形式存储在客户端应用程序中,描述应该是使用密钥容器中的非对称密钥完成.不幸的是,这使得CRL UDF在这里无用 - 当我尝试在UDF中获取基于密钥容器的密钥时,我得到一个权限异常: …

sql-server encryption aes sql-server-2008 ef-migrations

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

Perl - SQLite3数据库加密

我成功地使用Perl :: DBI模块使用Perl创建了一个SQLite3数据库.我想知道是否有办法将数据库的加密添加到我现有的Perl代码中?

我仔细阅读了以下2个链接:

但提供的示例似乎只包括专有软件或C#代码(特别是这一点/sf/answers/1704459081/).

提前致谢.

database sqlite encryption perl

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

BadPaddingException在Android中解密加密的数据

我是Android安全概念的新手。

我一直在阅读一些博客,以了解我们可以使用公钥加密数据并可以使用各自的私钥解密数据。加密似乎没有任何问题,但是当我尝试对其进行解密时,它会抛出:

javax.crypto.BadPaddingException:错误:0407106B:rsa例程:RSA_padding_check_PKCS1_type_2:块类型不是02。

我的代码如下:

public String RSAEncrypt(final String plain, PublicKey publicKey ) throws NoSuchAlgorithmException, NoSuchPaddingException,
    InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, publicKey);
    byte [] encryptedBytes = cipher.doFinal(plain.getBytes());
    String encrypted = bytesToString(encryptedBytes);
    System.out.println("EEncrypted?????" + encrypted );
    return encrypted;
}

public String RSADecrypt(String encryptedBytes,PrivateKey privateKey ) throws NoSuchAlgorithmException, NoSuchPaddingException,
    InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException {
    Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    cipher1.init(Cipher.DECRYPT_MODE, privateKey);
    byte [] decryptedBytes = cipher1.doFinal(stringToBytes(encryptedBytes));

    String decrypted = new String(decryptedBytes);
    System.out.println("DDecrypted?????" + decrypted);
    return decrypted;
    }

public  String bytesToString(byte[] …
Run Code Online (Sandbox Code Playgroud)

java encryption android cryptography

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

加密处理器和协处理器之间的差异

我正在尝试使用加密和解密算法处理问题,我使用下面的程序来测试我的要求,我意识到一个奇怪的问题.

我正在使用polarssl来满足我的加密和解密需求.

当我使用此命令在intel处理器上使用icc编译器编译它时,此程序运行良好:(来自polarssl的aes.c)

icc Deneme.c aes.c -o deneme
Run Code Online (Sandbox Code Playgroud)

输出:

Encryption result, encrypted value:
11 22 7 86 a2 d3 ed 95 b9 14 c0 57 f7 af 5f dc 93 66 77 68 44 12 9f 1b 72 6a ea 51 b8 f7 1d a4
Decryption result, plain array:
a2 d8 69 9c 77 73 c7 5e 1d 3b 83 26 6e 2f 35 30 9d f0 f2 e5 0 0 0 0 0 0 0 0 0 0 0 …
Run Code Online (Sandbox Code Playgroud)

c encryption intel icc polarssl

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

openssl s_client和s_server密码不匹配

我正在启动一个服务器:

openssl s_server -accept 8888 -cert server.de.crt -key server.de.key -state -cipher 'ECDHE-RSA-AES128-GCM-SHA256'
Run Code Online (Sandbox Code Playgroud)

然后使用s_client从同一台机器连接:

openssl s_client -connect localhost:8888 -state -cipher 'ECDHE-RSA-AES128-GCM-SHA256'
Run Code Online (Sandbox Code Playgroud)

给我:

3077933256:error:140740B5:SSL routines:SSL23_CLIENT_HELLO:no ciphers available:s23_clnt.c:469:
Run Code Online (Sandbox Code Playgroud)

但openssl密码告诉我它可用,密钥也应该有效.当我在apache 2.4的同一台机器上使用相同的密钥时,我的浏览器使用ECDHE-RSA-AES128-GCM-SHA256.所以我尝试使用chrome浏览器访问s_server:

https://machineip:8888
Run Code Online (Sandbox Code Playgroud)

服务器说:

CIPHER is ECDHE-RSA-AES128-GCM-SHA256
Run Code Online (Sandbox Code Playgroud)

所以s_server和密钥确实支持密码,但s_client不支持?为什么?

更多调查显示,只有使用SHA-1签名的密码似乎在客户端工作...

PS:我遇到过这个问题,因为我的node.js websocket服务器似乎也仅限于SHA-1密码.

encryption openssl sha1

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

Bcrypt,盐和成本是什么意思?

我一直使用MD5加密密码,但我读到它应该不再使用,而是使用bcrypt ..

我正在使用zendframework 2,在那里我发现它描述了bcrypt配置如下:

$bcrypt = new Bcrypt(array(
    'salt' => 'random value',
    'cost' => 11
));
Run Code Online (Sandbox Code Playgroud)

什么是盐,成本是多少?它们如何被使用?

encryption bcrypt zend-framework2

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

在c#alternative中cfusion_encrypt中填充的键是什么?

我找到了从C#复制c#中cfusion_encrypt函数的答案......

ColdFusion - cfusion_encrypt()和cfusion_decrypt() - C#替代品

但答案并没有说明用填充的键是什么使它与明文相同?任何人都可以建议用钥匙填充什么?无论是向右还是向左填充?

c# encryption coldfusion

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