标签: encryption

Android AES-128加密/解密文件非常慢.我怎样才能提高速度

我正在开发一个Android应用程序,可以保护像Vaulty和Keep安全的图像和视频.我正在尝试使用AES-128加密/解密技术来存储图像和视频.我通过分别拍摄尺寸为5.13,4.76和5.31的3个样本图像来尝试它.但加密消耗的时间分别为25秒,22秒,27秒,解密时间分别为31秒,30秒,34秒.我在HTC One X上测试它.

这样的速度对我的应用程序来说不可行,因为用户可以快速滚动和查看图像而不会中断.您能否建议我如何提高性能(速度)或者我应该切换到其他算法?你可以建议我使用任何其他技术,我可以快速加密/解密图像和视频,而不会过多地影响安全性.

我尝试了Vaulty并保持安全,而且它们非常快.据说Vaulty使用的是AES-256,但在加密和查看图像方面仍然非常快速且反应灵敏.vaulty如何快速使用AES-256?

我正在使用的代码是:

 static void encrypt(String filename) throws IOException, NoSuchAlgorithmException,
        NoSuchPaddingException, InvalidKeyException {

    // Here you read the cleartext.
    File extStore = Environment.getExternalStorageDirectory();
    startTime = System.currentTimeMillis();
    Log.i("Encryption Started",extStore + "/5mbtest/"+filename);
    FileInputStream fis = new FileInputStream(extStore + "/5mbtest/"+filename);
    // This stream write the encrypted text. This stream will be wrapped by
    // another stream.



    FileOutputStream fos = new FileOutputStream(extStore + "/5mbtest/"+filename+".aes", false);

    // Length is 16 byte
    SecretKeySpec sks = …
Run Code Online (Sandbox Code Playgroud)

encryption android cryptography bouncycastle aes

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

Java / Android中的数字签名(RSA密钥)

我想在我的java / android项目中使用存储在数据库中的私钥(RSA)生成数字签名。

我的2个密钥是使用以下代码生成的(项目正在生产中,我无法更改):

// Get keys pair (RSA)
KeyPair rsaKyePair = createKeyPair();

// Get private/ public keys and store them in DB
String pri = getPrivateKeyBase64Str(rsaKyePair);
String pub = getPublicKeyBase64Str(rsaKyePair));


public static KeyPair createKeyPair() {
    KeyPair keyPair = null;

    try {
        KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
        keygen.initialize(KEY_LENGTH);
        keyPair = keygen.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
    return keyPair;
}

public static String getPrivateKeyBase64Str(KeyPair keyPair){
    if (keyPair == null) return null;
    return getBase64StrFromByte(keyPair.getPrivate().getEncoded());
}

public static …
Run Code Online (Sandbox Code Playgroud)

java encryption android rsa digital-signature

5
推荐指数
0
解决办法
6106
查看次数

如何将RSA密钥转换为ssh-rsa

我正在尝试使用Apples安全框架将生成的公共RSA密钥转换为SSH.

这是我用于生成密钥对的代码:

- (void)generatePrivateKey {
    NSDictionary *privateKeyAttr = @{(__bridge id)kSecAttrIsPermanent: @YES,
                                     (__bridge id)kSecAttrApplicationTag: self.privateTag};
    NSDictionary *publicKeyAttr = @{(__bridge id)kSecAttrIsPermanent: @YES,
                                    (__bridge id)kSecAttrApplicationTag: self.publicTag};


    NSDictionary *keyPairAttr = @{(__bridge id)kSecAttrKeySizeInBits: @1024,
                                  (__bridge id)kSecAttrKeyType: (__bridge id)kSecAttrKeyTypeRSA,
                                  (__bridge id)kSecPrivateKeyAttrs: privateKeyAttr,
                                  (__bridge id)kSecPublicKeyAttrs: publicKeyAttr};

    SecKeyRef publicKey;
    SecKeyRef privateKey;

    SecKeyGeneratePair((__bridge CFDictionaryRef)keyPairAttr, &publicKey, &privateKey);
}

- (NSString *)getPublicKey {
    NSString *contents = [self keyForTag:self.publicTag];
    return [NSString stringWithFormat:@"-----BEGIN RSA PUBLIC KEY-----\n%@\n-----END RSA PUBLIC KEY-----", contents];
}

- (NSString *)getPrivateKey {
    NSString *contents = [self keyForTag:self.privateTag];
    return [NSString stringWithFormat:@"-----BEGIN …
Run Code Online (Sandbox Code Playgroud)

encryption ssh openssl openssh objective-c

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

复制过程中的pouch.transformation问题

我目前正在使用PouchDB(客户端)和CouchDB(服务器端)开发混合移动应用程序来进行数据存储.在我决定对存储在PouchDB中的数据实施安全性之前,一切都运行得非常顺利.为此我使用transform-pouch,我在传入方法中加密数据并在传出方法中解密数据.

以下是使用过的代码段.

 var transformFunctions = {
     incoming: function(doc) {
         Object.keys(doc).forEach(function(field) {
             if (field !== '_id' && field !== '_rev' && field !== '_revisions') {
                 if (service.isJsonObject(doc[field])) {
                     doc[field] = CipherService.encrypt(JSON.stringify(doc[field]), "password");
                 } else {
                     doc[field] = CipherService.encrypt(doc[field], "password");
                 }
             }
         });
         return doc;
     },
     outgoing: function(doc) {
         Object.keys(doc).forEach(function(field) {
             if (field !== '_id' && field !== '_rev' && field !== '_revisions') {
                 var decData = CipherService.decrypt(doc[field], "password");
                 if (service.isJsonString(decData)) {
                     doc[field] = JSON.parse(decData);
                 } else {
                     doc[field] = …
Run Code Online (Sandbox Code Playgroud)

javascript encryption couchdb pouchdb ionic-framework

5
推荐指数
0
解决办法
248
查看次数

创建使用Clear Key加密加密的可播放DASH视频

我正在尝试对Google Shaka播放器进行转码和DASH(使用Clear Key加密)示例H.264文件.我已经能够在线拼凑的每一组步骤都会在未加密的情况下生成可播放的版本,然后在我尝试加密时进行分解.

未加密

以下是我处理未加密版本的步骤:

  1. 将视频与音频分开

    ffmpeg -i input.mp4 -an -c copy video_only.mp4
    ffmpeg -i input.mp4 -map 0:2 -c copy audio_only.m4a
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将视频转码为工作变体(目前只有1个)

    ffmpeg -i video_only.mp4 -an -vcodec libx264 -s 1280x720 -c:v libx264 -b:v 384k -bf 2 -g 90 -sc_threshold 0 -an -strict experimental video_only_384kbps.mp4
    
    Run Code Online (Sandbox Code Playgroud)

3A.创建mpd

    MP4Box -dash 5000 -segment-name 'outputseg-%s' -url-template -bs-switching no \
        -out output.mpd -rap \
        audio_only.m4a \
        video_only_384kbps.mp4
Run Code Online (Sandbox Code Playgroud)

4A.将视频加载到Osmo4或Google Shaka中播放.

使用加密

现在,我尝试分层加密.从上面的第2步开始:

3B.使用Clear Key加密变体

    MP4Box -crypt drm.xml audio_only.m4a -out audio_only_encrypted.m4a
    MP4Box -crypt drm.xml …
Run Code Online (Sandbox Code Playgroud)

encryption video-streaming html5-video mpeg-dash

5
推荐指数
0
解决办法
3718
查看次数

在C#服务器和PHP客户端中使用RSA KeyPair

我有一个C#服务器,它将生成一个RSA KeyValue对.公钥将被发送到PHP客户端,然后将加密一些数据并发送到服务器.然后,服务器将使用它拥有的私钥进行解密.

我在C#中使用以下代码执行此操作 -

CspParameters cspParams = new CspParameters { ProviderType = 1 };

RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(1024, cspParams);

string publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false));
string privateKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(true));
Run Code Online (Sandbox Code Playgroud)

现在我需要将生成的公钥传递给PHP客户端.但问题是,当我在下面的函数中使用它时,PHP无法识别在C#中生成的Key String -

public function encrypt($data)
{
    $pubkey = 'BgIAAACkAABSU0ExAAIAAAEAAQBdZ3klDbVjH8oiBtGzHIMixo/TKPlv492kuau9chnARvkpxaRd8Qa82kIF2AvrEllhzjD07UHkVxoVZA2aYN+t'
    $pubKey4 = openssl_get_publickey(  $pubkey );

    openssl_public_encrypt($data, $encrypted, $pubKey4 )

}
Run Code Online (Sandbox Code Playgroud)

openssl_public_encrypt() 功能显示这样的警告:

警告:openssl_public_encrypt():key参数不是C:\ wamp\www\rsa\index.php中的有效公钥

请建议,PHP应识别的公钥格式是什么.

X509证书不是一个选项.

php c# encryption

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

laravel 4.2使用加密列进行查询

我目前在我的控制器中有这个代码,这里显示一组记录是我的代码

public function view()
{
    $title = "View Guardian Information";
    $vPa   = DB::table('dbo_guardianinformation')
                ->join('dbo_cities', 'dbo_guardianinformation.CityID', '=' , 'dbo_cities.CityID')
                ->select('dbo_guardianinformation.ParentAccountID','dbo_guardianinformation.FirstName','dbo_guardianinformation.LastName','dbo_guardianinformation.Roles',
                        'dbo_guardianinformation.Address','dbo_cities.CityName','dbo_guardianinformation.Status','dbo_guardianinformation.EmailAddress')
                ->get();
     //encrypt decrypt algo
    // $sptkey  = md5('sample_encryptkey');
    // $enPass  = rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $sptkey, $defPass, MCRYPT_MODE_ECB)));
    // $decPass = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $sptkey, base64_decode($enPass), MCRYPT_MODE_ECB));

    return View::make('ssims.view_parentAccount',compact('title','vPa'));
}
Run Code Online (Sandbox Code Playgroud)

我的问题是该列dbo_guardianinformation.Address包含加密记录我目前不知道我应该在哪里放置解密代码,以便当$vPa将传递给视图时它已经包含解密的记录.有任何想法吗?感谢任何愿意提供帮助的人

php encryption cryptography laravel laravel-4

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

如何解密用Laravel中的Crypt加密的Java(Android)文本?

我需要解密从服务器收到的一些数据,并且制作API的程序员将我引导到此Encrypter类,以查看他用于加密的内容.

现在基于该类,我发现使用的算法是AES128 CBC,我收到的字符串是Base64编码的,包含其他数据,而不仅仅是密文.

即,如果我收到以下字符串:

eyJpdiI6InJsSzRlU3pDZTBBUVNwMzdXMjVcL0tBPT0iLCJ2YWx1ZSI6Ik5JOENsSVVWaWk2RGNhNlwvWjJNeG94UzVkclwvMGJOREQreWUyS1UzclRMND0iLCJtYWMiOiJhZTZkYjNkNGM2ZTliNmU0ZTc0MTRiNDBmMzFlZTJhNTczZWIxMjk4N2YwMjlhODA1NTIyMDEzODljNDY2OTk2In0
Run Code Online (Sandbox Code Playgroud)

在base64解码后我得到:

{"iv":"rlK4eSzCe0AQSp37W25\/KA==","value":"NI8ClIUVii6Dca6\/Z2MxoxS5dr\/0bNDD+ye2KU3rTL4=","mac":"ae6db3d4c6e9b6e4e7414b40f31ee2a573eb12987f029a80552201389c466996"}
Run Code Online (Sandbox Code Playgroud)

基于line 99的Encrypter类(iv = base64_decode($payload['iv']);),I执行另一解码的base64上iv和value,并得到了一个iv长度为16的那些我作为参数下面的函数传递的:

    public static String decrypt(String iv, String encryptedData) throws Exception {
    byte[] keyValue = "zy2dEd1pKG5i3WuWbvOBolFQR84AYbvN".getBytes();
    Key key = new SecretKeySpec(keyValue, "AES");        
    Cipher c = Cipher.getInstance("AES/CBC/PKCS7Padding");
    c.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv.getBytes()));
    byte[] decordedValue = Base64.decode(encryptedData.getBytes(), Base64.DEFAULT);
    byte[] decValue = c.doFinal(decordedValue);
    return new String(decValue);
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

10-06 19:13:33.601 12895-12895/? W/System.err: java.security.InvalidAlgorithmParameterException: expected IV length of 16
10-06 19:13:33.601 12895-12895/? …
Run Code Online (Sandbox Code Playgroud)

php java encryption android cryptography

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

Microsoft Edge中的公钥加密

我有以下JavaScript代码使用Web Cryptography API实现公钥加密.它适用于Firefox和Chrome,但Microsoft Edge失败.我从Edge获得的错误是"由于错误80700011无法完成操作".我错过了什么?

<script>
    var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

    var crypto = window.crypto || window.msCrypto;
    var cryptoSubtle = crypto.subtle;

    cryptoSubtle.generateKey(
        {
            name: "RSA-OAEP",
            modulusLength: 2048, 
            publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
            hash: { name: "SHA-256" }, 
        },
        true, 
        ["encrypt", "decrypt"]
    ).then(function (key) { 
        console.log(key);
        console.log(key.publicKey);
        return cryptoSubtle.encrypt(
            {
                name: "RSA-OAEP"
            },
            key.publicKey,
            data
            );
    }).then(function (encrypted) { 
        console.log(new Uint8Array(encrypted));
    }).catch(function (err) {
        console.error(err);
    });
</script>
Run Code Online (Sandbox Code Playgroud)

encryption public-key-encryption webcrypto-api microsoft-edge

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

限制Laravel 5加密长度

我有一个Business Directory的Laravel5 Web应用程序.

当我加密像这样的值

$cryptval = Crypt::encrypt(1);

result  =  eyJpdiI6IndhaFZFNlhIRDlURzdXanJVMEhBM0E9PSIsInZhbHVlIjoidWF3VzRFZDhyRHltUlwveDdyV0VVWnc9PSIsIm1hYyI6IjE5YjA2YWIyN2Q0MTBlYjdhNDJiNDE5ZjY2OGQ2MDA2NzQ3ZTA4ODc4NzY0ZTIwMjBiMzQxN2RjNmM5ZDg3ZjYifQ==
Run Code Online (Sandbox Code Playgroud)

它给出了长约250长的弦.

有没有办法限制laravel中这个字符串的长度?

我的客户端需要在邮件功能中添加带加密值的URL.例如:www.example.com/varify/eyJpdiI6IndhaFZFNlhIRDlURzdXanJVMEhBM0E9PSIsInZhbHVlIjoidWF3VzRFZDhyRHltUlwveDdyV0VVWnc9PSIsIm1hYyI6IjE5YjA2YWIyN2Q0MTBlYjdhNDJiNDE5ZjY2OGQ2MDA2NzQ3ZTA4ODc4NzY0ZTIwMjBiMzQxN2RjNmM5ZDg3ZjYifQ==

但邮件功能只允许一些URL :(

php encryption laravel-5

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