标签: encryption

Objective#C等效代码的C#代码

我试图将用C#编写的代码转换为目标c,我试过但无法得到相同的结果.任何帮助都会很明显.

internal static class Common  {
    static string encryptionKey = "0C61L2FSL2F3E7X8E9T1L2F3E4O5";
    static byte[] salt = new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76};
         
    internal static string Encrypt(string clearText)
    {
        byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey, salt);

            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);

            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(clearBytes, 0, clearBytes.Length);
                    cs.Close();
                }
                clearText …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography objective-c

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

加密解密使用jasypt

如何使用加密密码解密jasypt.

package com.uk.mysqlmaven.jsf.test;

import org.jasypt.util.password.StrongPasswordEncryptor;
import org.jasypt.util.text.StrongTextEncryptor;


public class PasswordEncryptionDecryptionUsingJASYPT {
    public static void main(String[] args) {
        try {
            String password = "password";
            StrongPasswordEncryptor encryptor = new StrongPasswordEncryptor();
            String encryptedPassword = encryptor.encryptPassword(password);
            if (encryptor.checkPassword(password, encryptedPassword)) {
                //correct
                System.out.println("Encrypted: "+ encryptedPassword);
            } else {
                //bad again
                System.out.println("Error: ");
            }
            StrongTextEncryptor textEncryptor = new StrongTextEncryptor();
            textEncryptor.setPassword(encryptedPassword);
            String decryptedPassword = textEncryptor.decrypt(encryptedPassword);
            System.out.println("Decrypted: "+ decryptedPassword);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用jasypt解密密码时,控制台中会显示错误.

Encrypted: JIOYXNa1+3+QefY2S7sas7LmhyOuDQcG8TTsQoTkqj0OtobCvwAFHXxoTr7z6HuP
org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. …
Run Code Online (Sandbox Code Playgroud)

java encryption jasypt java-7 windows-8

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

Android密钥库 - 如果用户密钥设置为该用户,则可以由root用户检索用户密钥吗?

从Android 4.3开始,Android就拥有了自己的密钥库,我可以在其中存储密钥并在以后用于加密/解密.

据说这里和这里每个键只能由其所有者进行检索,甚至没有根可以得到它.

我的问题是:我不能写一个程序,将我的uid切换到密钥的所有者,检索它,然后用它来解密我不应该访问的数据?

编辑:添加了对密钥库文档的引用.

security encryption android android-keystore

7
推荐指数
2
解决办法
3253
查看次数

在解密期间获取"EVP_DecryptFinal_ex:错误的最终块长度"

我按照本教程加密和解密android/java中的简单字符串:

/sf/ask/302364751/ 我做了一个Cryptography类:

public class Cryptography {

    public static SecretKey generateKey() throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("SHA");
        digest.update("BhLKTyLoP YroUsRQT".getBytes());
        return new SecretKeySpec(digest.digest(), 0, 16, "AES");
    }

    public static byte[] encrypt(String message, SecretKey key) throws NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException, UnsupportedEncodingException {
        Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding");
        aes.init(Cipher.ENCRYPT_MODE, key);
        return aes.doFinal(message.getBytes());
    }

    public static String decrypt(byte[] cipherText, SecretKey key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding");
        aes.init(Cipher.DECRYPT_MODE, key);
        return new String(aes.doFinal(cipherText));
    }

}
Run Code Online (Sandbox Code Playgroud)

我能够加密方法并给了我这个:

Encrypted username: [B@52aff408 …
Run Code Online (Sandbox Code Playgroud)

java encryption android cryptography

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

WebRTC SRTP解密

我试图建立一个SRTP以RTP数据流转换器,我有得到的问题Master Key从WebRTC peerconnection我创造.

根据我的理解,通过DES交换,密钥是通过交换进行的SDP交换,并在a=crypto现场显示.因此,这种情况看起来非常简单(如果我错了,请纠正我),但最终无用,因为WebRTC标准化现在要求不应使用DES(Chrome现在只支持它,将来可能会删除).

对于DTLS,指纹字段中SDP是否有希望在未来交换中使用的证书的哈希值?[编辑:做了一些阅读后,我认为情况并非如此]我会想到的是指纹旁边的能力,通过交换中的DTLS数据包解析我应该能够抓住Master Key解码SRTP流,但我正在撞墙,因为我不知道在哪里看,甚至100%确定它是否是可能.

因此,简而言之,就是它甚至是可行的(并不进入下C++ API和创建我自己的实现的WebRTC)的解码SRTP是与创造的原料WebRTC PeerConnection中Chrome和FireFox(从收集到的信息嗅探可能通过分组SDP交换)?[编辑:令人沮丧,似乎访问密钥(也称为主密钥)的私有部分是不可能的......请大家指正,如果我错]

encryption des rtp dtls webrtc

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

比播种SecureRandom更好的创建AES密钥的方法

我需要将加密数据从Java客户端发送到C#服务器.现在我正在学习如何使用AES(要求)加密数据.继这个接受的答案用AES加密/解密我正在做以下事情:

byte[] keyStart = "qweroiwejrwoejlsifeoisrn".getBytes(); // Random character string

byte[] toEncrypt = myMessageString.getBytes();

keyGen = KeyGenerator.getInstance("AES");
sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(keyStart);
keyGen.init(128, sr);
SecretKey secretKey = keyGen.generateKey();
byte[] secretKeyByte = secretKey.getEncoded();

SecretKeySpec skeySpec = new SecretKeySpec(secretKeyByte, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
cipher.doFinal(toEncrypt);
Run Code Online (Sandbox Code Playgroud)

由于算法使用了一个SecureRandom使用keyStart我不知道这是否可以解码,C#甚至在另一个Java程序中解码,没有SecureRandom.

这个加密/解密是否能够只知道keyStart我正在使用的值或者因为SecureRandom我仍然需要传递其他东西才能解密?

还有,有更好的方法来做这个还是这个好吗?

c# java encryption cryptography

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

iOS和.NET产生不同的AES256结果

我已经在这几天了.我最初(也是最终)的目标是在iOS上使用CommonCrypto来加密具有给定IV和密钥的密码,然后使用.NET成功解密它.经过大量的研究和失败,我已经缩小了我的目标,即在iOS和.NET上简单地生成相同的加密字节,然后从那里开始.

我在.NET(C#,framework 4.5)和iOS(8.1)中创建了简单的测试项目.请注意,以下代码并非旨在保证安全,而是在较大的流程中将变量放大.此外,iOS是变量.最终的.NET加密代码将由客户端部署,因此我可以将iOS加密排除在外.除非确认不可能,否则.NET代码不会更改.

相关的.NET加密代码:

    static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
    {
        byte[] encrypted;
        // Create an Aes object 
        // with the specified key and IV. 
        using (Aes aesAlg = Aes.Create())
        {
            aesAlg.Padding = PaddingMode.PKCS7;
            aesAlg.KeySize = 256;
            aesAlg.BlockSize = 128;

            // Create an encryptor to perform the stream transform.
            ICryptoTransform encryptor = aesAlg.CreateEncryptor(Key, IV);

            // Create the streams used for encryption. 
            using (MemoryStream msEncrypt = new MemoryStream())
            {
                using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) …
Run Code Online (Sandbox Code Playgroud)

.net c# encryption aes ios

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

解密TLS 1.2 AES-GCM数据包

我正在开发一个Java程序来解密使用密码的TLS 1.2 Session TLS_RSA_WITH_AES_128_GCM_SHA256.我使用wireshark录制了一个测试会话.该主密钥是已知的.

No.     Time           Protocol Length Info
      4 0.000124000    TLSv1.2  166    Client Hello
      6 0.000202000    TLSv1.2  1074   Server Hello, Certificate, Server Hello Done
      8 0.001071000    TLSv1.2  393    Client Key Exchange, Change Cipher Spec, Finished
      9 0.003714000    TLSv1.2  301    New Session Ticket, Change Cipher Spec, Finished
     11 6.443056000    TLSv1.2  116    Application Data
     12 6.443245000    TLSv1.2  765    Application Data
     15 6.443390000    TLSv1.2  103    Alert (Level: Warning, Description: Close Notify)
Run Code Online (Sandbox Code Playgroud)

Packet 11包含HTTP GET Request 我正在尝试解密的内容. …

java encryption ssl bouncycastle aes-gcm

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

使用.NET 4.5(System.IdentityModel)/ WIF解密SAML 2断言

我正在尝试解密从基于Java的身份提供程序发出的加密SAML 2.0断言.

鉴于以下安全令牌处理程序的设置:

X509Certificate2 cert = ... // Contains private key
var serviceTokens = new List<SecurityToken>();
serviceTokens.Add(new X509SecurityToken(cert));

var issuers = new ConfigurationBasedIssuerNameRegistry(); 
issuers.AddTrustedIssuer("...thumbprint...", "nottherealname");

var configuration = new SecurityTokenHandlerConfiguration
            {
                AudienceRestriction = { AudienceMode = AudienceUriMode.Never },
                CertificateValidationMode = X509CertificateValidationMode.None,
                RevocationMode = X509RevocationMode.NoCheck,
                IssuerNameRegistry = issuers,
                MaxClockSkew = TimeSpan.FromMinutes(5),
                ServiceTokenResolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(serviceTokens.AsReadOnly(), false)
            };

var tokenHandlers = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection(configuration);
Run Code Online (Sandbox Code Playgroud)

我得到一个加密的SAML断言,例如:

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
  <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
    <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
      <xenc:EncryptedKey>
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
        <xenc:CipherData>


    <xenc:CipherValue>Fwhv/zEVi3eQvQN372L1S+pVDM5JKs1Kc2I25djuiOPdwKReCXRhnd5QL4Y8wJDWZ5vAlOxHkNAZ
OwOg4NsSI8KssrygNk4fwvNdVAGMB5ytI1QTGRqG6WwP4Em+uLN3VXbqiLWA9D6uO0BwATF9HdTb
j/IMhGCxZ1ZKrKQF5OL2PHKf4DqyNa5d9CNZenhYyYghgYrhgZtQVl/VARAp9VKsM/lbkPsEU8Ty
ow4LnTlYqBnykrOEJowN5B+HXGvfhbIBHyGzdCC+WbcEbI898zy/VhZ63VyFL2GSTdDWv10IEMy5
CHom4Qruer1xpyQMrxJ6EK30HMhVppToivgoFQ==</xenc:CipherValue> …
Run Code Online (Sandbox Code Playgroud)

c# encryption wif saml-2.0

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

在Coldfusion中加密,然后在PHP中解密

我有一个问题,复制PHP和Coldfusion生成的相同结果.

在PHP加密这种方式:

<?php
    $key = "$224455@";
    $Valor = "TESTE";

    $base = chop(base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, $Valor, MCRYPT_MODE_ECB)));     
?>
Run Code Online (Sandbox Code Playgroud)

我有结果:

TzwRx5Bxoa0 =

在Coldfusion这样做:

<cfset Valor = "TESTE">
<cfset Key = "$224455@">
<cfset base = Encrypt(Valor,ToBase64(Key),"DES/ECB/PKCS5Padding","BASE64")>
Run Code Online (Sandbox Code Playgroud)

结果:

qOQnhdxiIKs =

什么不是ColdFusion产生与PHP相同的价值?

非常感谢你

php encryption coldfusion coldfusion-11

7
推荐指数
2
解决办法
982
查看次数