标签: encryption

有效的密码加密

我已经看了StackOverflow问题,"密码加密/数据库层AES或应用层AES",我想在注册(web app)上有效地哈希我的密码然后能够检查它们是登录时更正.我正在使用VB,但使用C#很舒服.

我很乐意使用Jeff Atwood的".NET Encryption Simplified"中描述的加密类,因为它非常容易理解.它有一个散列类 - 但我不知道如何"登录"并在散列后比较散列.这是Jeff使用他的Encryption类演示他的哈希方法:

Sub DemoHash()
    Dim d As New Encryption.Data( _
        "{ts '2004-10-09 08:10:04'}The world is beautiful and needs caring by its children")

    Dim hash As New Encryption.Hash(Encryption.Hash.Provider.SHA1)
    Dim hash2 As New Encryption.Hash(Encryption.Hash.Provider.SHA256)
    Dim hash3 As New Encryption.Hash(Encryption.Hash.Provider.SHA384)
    Dim hash4 As New Encryption.Hash(Encryption.Hash.Provider.SHA512)
    Dim hash5 As New Encryption.Hash(Encryption.Hash.Provider.MD5)
    Dim hash6 As New Encryption.Hash(Encryption.Hash.Provider.CRC32)

    hash.Calculate(d)
    hash2.Calculate(d)
    hash3.Calculate(d)
    hash4.Calculate(d)
    hash5.Calculate(d)

    Console.WriteLine("SHA1:   " & hash.Value.Hex)
    Console.WriteLine("SHA256: " & hash2.Value.Hex)
    Console.WriteLine("SHA384: " & hash3.Value.Hex)
    Console.WriteLine("SHA512: …
Run Code Online (Sandbox Code Playgroud)

asp.net security encryption hash

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

无法在Java和PHP之间交换使用AES-256加密的数据

我的问题是:我在Java中加密的东西我可以在Java中完美解密,但PHP mcrypt无法解密.我加密的内容mcrypt可以解密mcrypt,但不能用Java 解密.

我想从Java应用程序发送和接收加密数据到PHP页面,所以我需要它兼容.

这是我的...

JAVA ...

public static String crypt(String input, String key){
    byte[] crypted = null;
    try{
        SecretKeySpec skey = new SecretKeySpec(Base64.decodeBase64(key), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, skey);
        crypted = cipher.doFinal(input.getBytes());
    }catch(Exception e){
    }
    return Base64.encodeBase64String(crypted);
}

public static String decrypt(String input, String key){
    byte[] output = null;
    try{
        SecretKeySpec skey = new SecretKeySpec(Base64.decodeBase64(key), "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, skey);
        output = cipher.doFinal(Base64.decodeBase64(input));
    }catch(Exception e){
    }
    return new String(output);
}
Run Code Online (Sandbox Code Playgroud)

运行: …

php java encryption aes

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

Windows Phone 7 - 带加密的SQLite

我在Windows Mobile中使用System.Data.SQLite for SQLite.它具有内置的加密支持.我已经为Windows Phone 7找到了许多SQLite实现.但是,它们都没有内置的加密支持.有谁知道支持加密的Windows Phone 7的任何SQLite实现?

c# sqlite encryption windows-phone-7

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

获取异常java.security.InvalidKeyException:无效的AES密钥长度:29个字节?

当在程序下面运行时,我得到了这个例外.无法弄清楚AES的问题是什么允许128 -256位密钥?

 Exception in thread "main" java.security.InvalidKeyException: Invalid AES key length: 29 bytes
at com.sun.crypto.provider.AESCipher.engineGetKeySize(DashoA13*..)
at javax.crypto.Cipher.b(DashoA13*..)
Run Code Online (Sandbox Code Playgroud)

在第20行获得例外

这是程序

 import java.security.Key;

 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;

 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;

 public class AESEncryptionDecryptionTest {

   private static final String ALGORITHM       = "AES";
   private static final String myEncryptionKey = "ThisIsSecurityKey";
   private static final String UNICODE_FORMAT  = "UTF8";

   public static String encrypt(String valueToEnc) throws Exception {
 Key key = generateKey();
 Cipher c = Cipher.getInstance(ALGORITHM);
 c.init(Cipher.ENCRYPT_MODE, key);  //////////LINE 20
 byte[] encValue = c.doFinal(valueToEnc.getBytes());
 String encryptedValue …
Run Code Online (Sandbox Code Playgroud)

java encryption aes

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

System.Security.Cryptography与Windows.Security.Cryptography

我是一个新的Windows 8开发人员,我有一些专为Linux设计的代码,但只要安装了GTK#,就可以在Windows上运行.

我目前正在将该应用程序移植到Windows 8作为Modern UI(Metro)应用程序.它很顺利,除了当我尝试导入我的密钥派生代码(它获取用户的密码并从中获取密钥256位密钥)时,Visual Studio Ultimate 2013表明它无法识别using System.Security.Cryptography.

在查看Windows 8开发人员网站后,我发现有一个新类Windows.Security.Cryptography,但是,它似乎也没有被Visual Studio识别.

所以,既然你有背景,我有几个问题:

  1. System.Security.Cryptography在Windows 8中可用吗?如果是这样,是否支持RT版本?如何让Visual Studio识别它?
  2. Windows.System.Security是如何不同的,是否有与Rfc2898DeriveBytes兼容的类/方法?通过兼容,我的意思是给出相同的密码和盐是有一种方法来获得相同的密钥作为结果.

为了澄清我想要做什么,我的密钥派生代码发布如下:

public class GetKey
{
    // constructor
    public GetKey (bool use=true, string password="none")
    {   if (use == true)
        {
            this.genSalt();
            byte[] salt = this.salt;
            Rfc2898DeriveBytes pwdKey = new Rfc2898DeriveBytes(password, salt, 4000);
            this.key = pwdKey.GetBytes(32);
            this.iv = pwdKey.GetBytes(16);
        }
    }

    // properties
    private byte[] key;
    private byte[] iv;
    private byte[] salt;

    // methods
    public void retrieveKey(string password)
    {
        try 
        { …
Run Code Online (Sandbox Code Playgroud)

c# encryption windows-8

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

在Android和IPhone中使用AES-128进行加密(结果不同)

我试图在Android和IPhone平台上使用AES算法加密一些文本.我的问题是,即使使用相同的加密/解密算法(AES-128)和相同的固定变量(密钥,IV,模式),我在两个平台上都会得到不同的结果.我包括来自两个平台的代码示例,我用它来测试加密/解密.我很感激在确定我做错了什么方面有所帮助.

  • 关键:"123456789abcdefg"
  • 四:"1111111111111111"
  • 纯文字:"HelloThere"
  • 模式:"AES/CBC/NoPadding"

Android代码:

public class Crypto {
    private final static String HEX = "0123456789ABCDEF";

    public static String encrypt(String seed, String cleartext)
            throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] result = encrypt(rawKey, cleartext.getBytes());
        return toHex(result);
    }

    public static String decrypt(String seed, String encrypted)
            throws Exception {
        byte[] rawKey = getRawKey(seed.getBytes());
        byte[] enc = toByte(encrypted);
        byte[] result = decrypt(rawKey, enc);
        return new String(result);
    }

    private static byte[] getRawKey(byte[] seed) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("CBC");
        SecureRandom sr …
Run Code Online (Sandbox Code Playgroud)

java iphone encryption android aes

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

SOAPUI证书身份验证

我正在尝试访问远程Web服务并检查该服务是否正常工作.要点击服务我正在使用SOAPUI客户端.我第一次尝试时,得到了403/Forbidden响应.开发远程服务的团队为我提供了用于发出请求的数字证书.我该如何使用此证书发出请求.我对在Web服务身份验证中使用数字证书以及soap ui的概念相当新.

authentication encryption web-services certificate soapui

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

在Android上使用AES加密文件

所以我正在为自己制作个人项目,我正在尝试加密手机上的文件.这些文件可以是任何东西,例如文档,照片等.现在我正在尝试使其正常工作.当我运行加密时,它似乎正常工作并加密文件.当我运行解密时,有时它会起作用,有时却不起作用.当它失败时,我通常会在"敲定密码,填充块损坏"错误时出现"错误".我也没有使用不同的测试文件,因此它不像某些文件有效,而有些则不然.这是我每次尝试的两个文件.

public static void encryptfile(String path,String Pass) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
    FileInputStream fis = new FileInputStream(path);
    FileOutputStream fos = new FileOutputStream(path.concat(".crypt"));
    byte[] key = (salt + Pass).getBytes("UTF-8");
    MessageDigest sha = MessageDigest.getInstance("SHA-1");
    key = sha.digest(key);
    key = Arrays.copyOf(key,16);
    SecretKeySpec sks = new SecretKeySpec(key, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, sks);
    CipherOutputStream cos = new CipherOutputStream(fos, cipher);
    int b;
    byte[] d = new byte[8];
    while((b = fis.read(d)) != -1) {
        cos.write(d, 0, b);
    }
    cos.flush();
    cos.close();
    fis.close();
}

public static …
Run Code Online (Sandbox Code Playgroud)

java encryption android

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

NSCharacterSet URLHostAllowedCharacterSet不替换'+'符号?

我正在努力通过网络传输长加密字符串并让它们在服务器上正确传出.例如,我在客户端上有这个加密的字符串:

wcWSERZCh8Xm1hpbNo1kSD1LvFmpuUr4wmq9hQUWeK0vYcLeFPGwFR/sBTES1A4rPV6eyp9nzEEU9uKkiFSTdP + SPOSqUf6evjf3WRHrXMRe81lIrHuRyk0iRwoNe5uIk + VlpR41kETmznXa4 + gELmf53r7oayRkkffnIPDmpO + WbgE0VL3PQeOsXB01tWJyDiBIsz5WJiiEIm3ZoJW/SW ==

正如你所看到的,它不会没有一些URL编码通过网络传输(几个字符+和/,最显着的).我不完全确定在其他情况下是否会出现其他角色,所以我想确保我的解决方案"普遍"正确.我正在使用这一行:

NSString *escapedString = [cipherString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
Run Code Online (Sandbox Code Playgroud)

我在高度评价的答案中找到了.

但是,我仍然无法在服务器端解密此问题,因此我在发送之前立即在客户端上打印出结果,我看到了:

wcWSERZCh8Xm1hpbNo1kSD1LvFmpuUr4wmq9hQUWeK0vYcLeFPGwFR%2FsBTES1A4rPV6eyp9nzEEU9uKkiFSTdP + SPOSqUf6evjf3WRHrXMRe81lIrHuRyk0iRwoNe5uIk + VlpR41kETmznXa4 + gELmf53r7oayRkkffnIPDmpO + WbgE0VL3PQeOsXB01tWJyDiBIsz5WJiiEIm3ZoJW%2Fsw ==

为什么'+'标志仍然存在?我使用了错误允许的字符集吗?我应该使用哪个字符集来保证我正确地逃避所有有问题的字符?

如果它有帮助,这里是我用来加密纯文本字符串的代码.完成后,我在通过网络发送之前对结果进行base64编码:

- (NSData *)phpEncryptCleartext : (NSData *)cleartext
{
    NSData *cleartextPadded = [self phpPadData:cleartext];

    CCCryptorStatus ccStatus        = kCCSuccess;
    size_t          cryptBytes      = 0;    // Number of bytes moved to buffer.
    NSMutableData  *cipherTextData  = [NSMutableData dataWithLength:cleartextPadded.length];

    ccStatus = CCCrypt(kCCEncrypt,
                       kCCAlgorithmAES128,
                       0,
                       _sessionKey.bytes,
                       kCCKeySizeAES128,
                       _iv.bytes,
                       cleartextPadded.bytes,
                       cleartextPadded.length, …
Run Code Online (Sandbox Code Playgroud)

encryption objective-c url-encoding

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

ASPNET_REGIIS:将AES密钥和IV放入KeyContainer

是否可以使用ASPNET_REGIIS将AES密钥和IV放入KeyContainer?如果有,怎么样?

语境:

我创建了AesProtectedConfigurationProvider来使用AES加密web.config数据,而不是使用Triple DES(即3DES).我还创建了一个使用AesProtectedConfigurationProvider的控制台应用程序,以生成AES密钥和初始化向量(IV).我可以将密钥保存到文本文件,然后在web.config的提供程序中引用该文本文件.从那里,我可以加密web.config文件.但是,如果可能的话,我想通过将keys.txt文件移动到KeyContainer中来保护它们.

因此,在provider标记下,keyContainerName的部分将是:

keyContainerName="AesKeyContainer" 
Run Code Online (Sandbox Code Playgroud)

而不是

keyContainerName="C:\AesKey.txt"
Run Code Online (Sandbox Code Playgroud)

我的理解是ASPNET_REGIIS中现有的加密产品现在使用3DES加密web.config文件的内容,而RsaProtectedConfigurationProvider用于加密3DES密钥(如果我错了,请纠正我).因此,如果可以使用RsaProtectedConfigurationProvider将AES密钥加密到KeyContainer中,那么这将是有帮助的.我查看了以下网站,我不确定这是否可行:

https://msdn.microsoft.com/en-us/library/33ws57y0.aspx

如何使用AES而不是3DES加密web.config

编辑: 有谁知道为什么微软在.NET的后续版本中拿出了AesProtectedConfigurationProvider?这似乎是一个倒退,因为AES是当前的标准,而不再推荐3DES.在与同事交谈时,他们提到可能由于安全漏洞而被删除,例如; 特权提升.众所周知,微软在安全方面做出了未经通知的变更.但是,我想知道是否有人确切知道.如果确实在AesProtectedConfigurationProvider中发现了一个缺陷,那么我可能倾向于继续使用3DES.

c# asp.net encryption cryptography

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