这可能更适合security.stackexchange.com,但我特别好奇PHP.
我在应用程序中使用openssl,我注意到openssl资源的免费操作.这很可能只是一个通用的内存版本,但鉴于加密性质,它可以作为特殊情况处理.
应用程序空间内的AFAIK无法确保从内存中删除变量.但是,在Zend的土地上,C扩展是否会清除已知的敏感数据,还是只释放内存?是否openssl_pkey_free安全释放内存?我怎样才能断言它已被安全发布以将其应用于我将来可能会对其他扩展程序?
我不是安全分析师,所以我对安全的定义相当含糊.
我正在使用xampp和windows以及laravel,一切都运行良好,但是当我完成工作并转向xampp并尝试今天早上打开我的工作时,这就是我得到的:
FatalThrowableError in Encrypter.php line 100:
Fatal error: Call to undefined function Illuminate\Encryption\openssl_decrypt()
Run Code Online (Sandbox Code Playgroud)
Encrypter.php是一个标准的laravel文件,我甚至没有触及它.我的分机已开启.
延长= php_openssl.dll
可能有什么问题?
我运行一个网站,我们将某些帐户标记为诈骗者,并"标记"他们的帐户和所有用作坏帐户的信用卡.我们不存储实际的信用卡值,而是存储校验和/ MD5算法.
我们现在一直在碰撞.存储这些值的最佳方法是什么 - 不可逆,但能够对未来值进行比较.
我认为MD5会是最好的,但我们在这里进行辩论......
对于我的iPhone应用程序,Apple想知道我的密码加密(md5)是否大于64位对称或大于1024位对称.我无法在网上找到它,所以我想知道是否有人知道答案.另外,这被认为是适用于密码的加密技术,还是应该使用不同的东西?
谢谢你的帮助!
我需要计算字符串的哈希码并将其存储到'long'变量中.
MD5和SHA1产生的哈希码长度超过64位(MD5 - 128位,SHA1 - 160位).
想法任何一个?
干杯,
多伦
这是对这个问题的跟进,但我正在尝试将C#代码移植到Java而不是Ruby代码到C#,就像相关问题中的情况一样.我正在尝试验证从Recurly.js api返回的加密签名是否有效.不幸的是,Recurly没有Java库来协助验证,所以我必须自己实现签名验证.
根据上面的相关问题(this),以下C#代码可以生成验证Recurly返回的签名所需的哈希:
var privateKey = Configuration.RecurlySection.Current.PrivateKey;
var hashedKey = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(privateKey));
var hmac = new HMACSHA1(hashedKey);
var hash = hmac.ComputeHash(Encoding.ASCII.GetBytes(dataToProtect));
return BitConverter.ToString(hash).Replace("-", "").ToLower();
Run Code Online (Sandbox Code Playgroud)
Recurly在其签名文档页面上提供以下示例数据:
未加密的验证消息:[1312701386,transactioncreate,[account_code:ABC,amount_in_cents:5000,货币:美元]]
私钥:0123456789ABCDEF0123456789ABCDEF
结果签名:0f5630424b32402ec03800e977cd7a8b13dbd153-1312701386
这是我的Java实现:
String unencryptedMessage = "[1312701386,transactioncreate,[account_code:ABC,amount_in_cents:5000,currency:USD]]";
String privateKey = "0123456789ABCDEF0123456789ABCDEF";
String encryptedMessage = getHMACSHA1(unencryptedMessage, getSHA1(privateKey));
private static byte[] getSHA1(String source) throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] bytes = md.digest(source.getBytes("UTF-8"));
return bytes;
}
private static String getHMACSHA1(String baseString, byte[] keyBytes) throws GeneralSecurityException, …Run Code Online (Sandbox Code Playgroud) 这是我用来加密/解密数据的代码:
// Set the method
$method = 'AES-128-CBC';
// Set the encryption key
$encryption_key = 'myencryptionkey';
// Generet a random initialisation vector
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
// Define the date to be encrypted
$data = "Encrypt me, please!";
var_dump("Before encryption: $data");
// Encrypt the data
$encrypted = openssl_encrypt($data, $method, $encryption_key, 0, $iv);
var_dump("Encrypted: ${encrypted}");
// Append the vector at the end of the encrypted string
$encrypted = $encrypted . ':' . $iv;
// Explode the string using the `:` separator.
$parts …Run Code Online (Sandbox Code Playgroud) 情况:我有一个元素数量可变的多维数组。例如
array(N) {
0 => array(3) { ... },
1 => array(8) { ... },
2 => array(1) { ... },
...
M => array(12) { ... },
...
N-1 => array(7) { ... }
}
Run Code Online (Sandbox Code Playgroud)
我想找到这个子数组中元素的最大数量(在上面的例子中,它是 12)。一个简单的解决方案是 O(N) 线性搜索。
<?php
function max_length($2d_array) {
$max = 0;
foreach($2d_array as $child) {
if(count($child) > $max) {
$max = count($child);
}
}
return $max;
}
Run Code Online (Sandbox Code Playgroud)
但是,我不禁想知道是否有一些聪明的技巧可以优化此查找。所以我的问题是一个两部分(尽管对任一部分的答案都可以解决它):
我目前在我的控制器中有这个代码,这里显示一组记录是我的代码
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将传递给视图时它已经包含解密的记录.有任何想法吗?感谢任何愿意提供帮助的人
升级到php7后,BCryptPasswordEncoder会抛出以下错误,例如在使用FOSUserBundle标准注册页面时注册:
"在C:\ xampp\htdocs\ascentary\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder.php第81行"C:不推荐使用'salt'选项来使用password_hash XAMPP\htdocs中\ testproject \供应商\贝哈特\贝哈特的\ src \贝哈特\试验工作\电话\处理器\ RuntimeCallHandler".
我已经跟踪了这个问题,问题是FOS UserManager类,它调用:
/**
* {@inheritDoc}
*/
public function updatePassword(UserInterface $user)
{
if (0 !== strlen($password = $user->getPlainPassword())) {
$encoder = $this->getEncoder($user);
$user->setPassword($encoder->encodePassword($password, $user->getSalt()));
$user->eraseCredentials();
}
}
Run Code Online (Sandbox Code Playgroud)
在这里传递$ user-> getSalt()会抛出错误,因为在php7中,不再允许您将自定义salt传递给bcrypt encoding/password_hash函数.另外,我在基本fos用户实体中看到一个问题,因为在其构造函数中,salt设置为:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
Run Code Online (Sandbox Code Playgroud)
问题:
(1)如何解决我上面发布的错误?也许覆盖了UserManager,或者是否有fos提供的解决方案?
(2)如何正确保护盐,即自动生成?
(3)是否还需要其他更新,例如更新ircmaxell lib?