我有一个128位ID,我想要执行单向散列,但我不想为输入消息获得相同的摘要.有没有人知道sha-1或替代方案是否保证不会产生小于其输出摘要大小的消息集的冲突?这至少在理论上是可能的......
我还考虑过使用RSA,丢弃私钥给我一个单向加密,但是我需要将结果存储在一个32 char数据库字段中,而我可用的加密方案不会产生足够小的东西.
任何关于产生原始值的确定性,不可逆和无碰撞变换的方法的建议都是受欢迎的.
在处理从中/dev/urandom生成随机字节的项目时,建议我检查以确保它/dev/urandom不仅仅是一个文件.
最直接的方式似乎是这样的:
/**
* Is the given file a device?
*
* @param string|resource $file
* @return boolean
*/
function is_device($file)
{
if (is_resource($file)) {
$stat = fstat($file);
} elseif (is_readable($file) && !is_link($file)) {
$stat = stat($file);
} else {
return false;
}
return $stat['rdev'] !== 0;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是双重的:
$stat['rdev'] !== 0检查失败的情况?重要提示:我需要的解决方案必须是PHP,而不依赖于任何PECL扩展或自定义C代码.该项目是PHP 7的纯PHP 5填充random_bytes()和random_int()函数,可以由Composer安装在任何其他人的PHP 5项目中.
我想要的是能够获得特定密码的sha1哈希值.
所以,例如,如果我的密码是"你好",我需要输入什么命令到linux来获取hello的sha1散列值?
我试过了
echo -n "hello" | sha1sum
Run Code Online (Sandbox Code Playgroud)
但它返回的值没有给出数据库存储过程接受的值,该值接受散列值来验证登录(该问题不在此存储过程中,因为我们在整个地方使用它来进行验证) .
基本上,
我只需要知道一个命令来给出一个字符串并获取它的sha1哈希值
谢谢!:)
我有一小段一些数据(小于1kb),我希望用户代理从我的网站发送到其他网站.为了让其他站点验证我是创建字符串的那个,我有两个选项.
我不想设置HMAC,因为这意味着我必须为每个站点使用自定义键,这将是一个痛苦.
在这两个选择中,似乎#2会节省带宽,这使它看起来是更好的选择.
那么如何使用PHP设置公钥/私钥加密,是否有任何缺点?
所以我需要在Objective-C中生成一个Sha256密码,并且无法弄清楚我的生活怎么做!有什么容易的东西,我只是缺少?
我已经尝试实现以下方法(这是为iPhone编写的,但我想也许它可以跨平台工作,就像一些Objective-C代码那样)
-(NSString*)sha256HashFor:(NSString*)input
{
const char* str = [input UTF8String];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(str, strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH*2];
for(int i = 0; i<CC_SHA256_DIGEST_LENGTH; i++)
{
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}
Run Code Online (Sandbox Code Playgroud)
但这只是吐出有关CC_SHA256_DIGEST_LENGTH是未声明标识符的错误.
当我尝试使用CI加密库加密字符串时,返回的字符串非常大,大约178个字符长.是否有任何方法可以减少字符串的长度.默认密码是:AES-128.
假设:$data=$this->encryption->encrypt("welcome to ooty");
它返回178长度的字符串值..我需要它减少到20以下
更新:当我加密一个数字时,比如6,它返回178个长字符串.
php encryption cryptography codeigniter encryption-symmetric
MySQL中的下一个功能
MD5( 'secret' )生成5ebe2294ecd0e0f08eab7690d2a6ee69
我想有一个Java函数来生成相同的输出.但
public static String md5( String source ) {
try {
MessageDigest md = MessageDigest.getInstance( "MD5" );
byte[] bytes = md.digest( source.getBytes("UTF-8") );
return getString( bytes );
} catch( Exception e ) {
e.printStackTrace();
return null;
}
}
private static String getString( byte[] bytes ) {
StringBuffer sb = new StringBuffer();
for( int i=0; i<bytes.length; i++ ) {
byte b = bytes[ i ];
sb.append( ( int )( 0x00FF & b ) );
if( …Run Code Online (Sandbox Code Playgroud) 我试图解决这个问题,但我从来没有找到适合我的解决方案.问题是我正在接受有关BASE64Encoder的警告.没有BASE64Encoder,有没有其他方法可以做到这一点?
代码:
public static String Encrypt(String Data) throws Exception
{
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
String encryptedValue = new BASE64Encoder().encode(encVal); //Here is the problem
return encryptedValue;
}
public static String Decrypt(String encryptedData) throws Exception
{
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData); //Another problem
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
private static Key generateKey() throws Exception
{ …Run Code Online (Sandbox Code Playgroud) 我有以下用Java编写的代码
Mac mac = Mac.getInstance("HmacSHA1");
String secretKey ="sKey";
String content ="Hello";
byte[] secretKeyBArr = secretKey.getBytes();
byte[] contentBArr = content.getBytes();
SecretKeySpec secret_key = new SecretKeySpec(secretKeyBArr,"HmacSHA1");
byte[] secretKeySpecArr = secret_key.getEncoded();
mac.init(secret_key);
byte[] final = mac.doFinal(contentBArr);
Run Code Online (Sandbox Code Playgroud)
我想在C#中做同样的例子.所以,我写了下面的代码
HMACSHA1 hmacsha1 = new HMACSHA1();
string secretKey = "sKey";
string content = "Hello";
byte[] secretKeyBArr = Encoding.UTF8.GetBytes(secretKey);
byte[] contentBArr = Encoding.UTF8.GetBytes(content);
hmacsha1.Key = secretKeyBArr;
byte[] final = hmacsha1.ComputeHash(contentBArr);
Run Code Online (Sandbox Code Playgroud)
最终结果并不相同.secretKeyBArr和contentBArr是字节数组,它们的值在两个示例中都相同.未知的是传递给mac.init()的SecretKeySpec.那么,什么是C#中相同的同类?
我需要用PHP加密/解密数据.我对此完全陌生,但我读过Libsodium-PHP是AES加密的最佳工具.就像我研究过的其他PHP加密库一样,Libsoduim-PHP似乎几乎没有提供如何使用该库的文档(我能够找到).任何有PHP加密经验的人都可以指向一个好的学习资源的方向,或者使用Libsoduim-PHP编写几行示例代码吗?
非常感谢你的帮助,
Atlas
cryptography ×6
java ×4
php ×4
sha1 ×3
cryptographic-hash-function ×2
encryption ×2
libsodium ×2
linux ×2
aes ×1
base64 ×1
bash ×1
bsd ×1
c# ×1
codeigniter ×1
encoding ×1
file-io ×1
filesystems ×1
hash ×1
hmac ×1
macos ×1
md5 ×1
mysql ×1
objective-c ×1
passwords ×1
pgp ×1
php-openssl ×1
rsa ×1
sha256 ×1
shell ×1