我有以下代码在PHP 5.5.9上运行良好.
function index()
{
echo $this->encryptText_3des('TEST','JHHKJH9879');
}
function encryptText_3des($plainText, $key) {
$key = hash("md5", $key, TRUE);
for ($x=0;$x<8;$x++) {
$key = $key.substr($key, $x, 1);
}
$padded = $this->pkcs5_pad($plainText,
mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
return $encrypted;
}
function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
Run Code Online (Sandbox Code Playgroud)
加密发生得很好.但是在5.6.9中,在mcrypt_encrypt的PHP文档中,他们提到了
不再接受无效的密钥和iv尺寸.mcrypt_encrypt()现在将抛出警告,如果输入无效,则返回FALSE.以前,键和IV用'\ 0'字节填充到下一个有效大小.
如何在不改变加密算法的情况下使用第五个参数修改当前代码?
我试过了
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
Run Code Online (Sandbox Code Playgroud)
给$ iv作为第五个参数.
但它没有成功.加密与早期加密不同.
我正在寻找Windows CE 6.0支持的可用密码套件的列表。
使用当前的SSL配置(ssllabs.com“ A等级”),旧的WinCE 6.0客户端将无法通过加密连接/ HTTPS与Web服务器进行通信。
因此,我想知道我需要为WinCE 6.0重新启用什么过时/不安全/弱算法(RC4?)和/或协议(SSLv3?)。
WinCE 6.0是否支持基于TLS 1.0的AES?
谢谢!
我正在尝试将Java(简单)加密algorythm移植到Node JS.我需要能够解密/加密从Java端加密/解密的东西.
我一开始就陷入困境,密码的初始化.
在Java中,我得到了密钥SecretKeySpec和初始化向量IvParameterSpec:
public CryptStuff(String password) throws zillion_exceptions {
if (password==null) throw new InvalidKeyException("No encryption password is set!");
key = new SecretKeySpec(password.getBytes("UTF-8"), "AES");
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
ivSpec=new IvParameterSpec(new byte[cipher.getBlockSize()]);
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);
}
Run Code Online (Sandbox Code Playgroud)
NodeJS需要一个密钥缓冲区和一个IV缓冲区,但是,我不知道如何从头开始计算它们:
var mCrypto = require('crypto'),
key=[0,0,0,0,0,0,.......],
iv=[0,0,0,0,0,.........];
function init (password) {
// generate key from password
// generate IV from blocksize?
var aesCipher = mCrypto.createCipheriv("aes-????????", (new Buffer(key)), (new Buffer(iv)));
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
另外,AES/CBC/PKCS5Padding的匹配算法字符串是什么?
我正在使用android应用程序,我需要将视频保存在SD卡中,并且不能将其传输,这就是为什么我在需要时进行加密和解密的原因Facebook Conceal,如果视频尺寸较小,则可以很好地工作。
每当我尝试对大型视频文件进行加密和解密10MB时GenyMotion running 2.3.7,崩溃不止于此,OutOfMemoryException这意味着我分配给我的应用程序的堆内存用光了,这是无法处理的,但必须防止。
尝试过:
Facebook隐藏:在解密时说
You must read the entire stream to completion.
The verification is done at the end of the stream.
Thus not reading till the end of the stream will cause
a security bug. For safety, you should not
use any of the data until it's been fully read or throw
away the data if an exception occurs.
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码进行加密和解密Facebook Conceal: …
我想在我的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) 我正在尝试使用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) 我目前正在使用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) 我有一个只有客户端的Java程序,可以调用Github的API服务器.您可能知道,对于未经身份验证的用户,Github的API访问限制为每小时60次.我想使用客户端密钥和客户端密钥将此限制提高到每小时5000个呼叫,但是如何防止使用我的客户端应用程序的其他人反编译代码并获取我的客户端密钥?
请注意,应用程序需要访问实际的客户端密钥和密钥,但我需要它们对用户隐藏.
正如标题所说,我想知道在给定RSA算法的情况下如何在多线程环境中最好地使用Cipher实例.
我已经阅读了关于这个主题的几个问题,以及我收集的内容:
密码不是线程安全的,因为它在加密/解密时保持内部状态
如果使用AES,doFinal()则将初始化向量重置为上一个已知值,因此每次都应生成新的Cipher实例
我的问题
cipher.init()如果选择的算法是RSA,是否可以只调用一次?这与第二个子弹相反,如下面的代码所示.我相信因为没有初始化向量.此外,密码仅用于解密数据.
我应该只在cipher.doFinal()调用时同步吗?
代码示例:
public class RsaPrototype {
private static PrivateKey privKey;
private static Cipher cipher;
private static final String PRIVATE_KEY_PATH ="./privK.pem";
/*
* ALGORITHM/BLOCKING_MODE/PADDING_SCHEMA
*/
private static final String CIPHER_SPECIFICATION = "RSA/None/NoPadding";
private static final String RSA_PROVIDER ="BC";
static {
Security.addProvider(new BouncyCastleProvider());
importPrivateKey();
cipher = getCipher();
}
/**
* Initializes cipher with RSA algorithm, without blocking mode and padding.
* Implementation provider is bouncy castle.
*
* @return cipher …Run Code Online (Sandbox Code Playgroud) 大多数人都使用这种解密和解码字。但是每当我问他们“解码和解密之间有什么区别?” 没有人能够以我想听的方式完美回答。我可以清楚一下吗?
encryption ×10
java ×4
android ×2
rsa ×2
aes ×1
apache ×1
couchdb ×1
cryptography ×1
decode ×1
decompiling ×1
facebook ×1
github ×1
javascript ×1
mcrypt ×1
node.js ×1
objective-c ×1
openssh ×1
openssl ×1
padding ×1
php ×1
php-5.6 ×1
pouchdb ×1
ssh ×1
ssl ×1
terminology ×1
windows-ce ×1