我从linux的'sha512sum'工具和python hashlib库中获得了不同的消息摘要.
这是我在Ubuntu 8.10上得到的:
$ echo test | sha512sum
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123 -
$ python
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.sha512("test").hexdigest()
'ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff'
Run Code Online (Sandbox Code Playgroud)
两者都应该计算字符串"test"的消息摘要,为什么你认为我得到的结果不同?
我试图在Ruby中用更长的字符串创建短的非碰撞字符串.最好的方法是什么?Base64编码MD5哈希?
这是用例:
loop do
key = short_hash("#{user_id}-#{timestamp}")
break if $redis.setnx(key, "0")
end
Run Code Online (Sandbox Code Playgroud)
我不希望钥匙太长.
在我的代码中,我需要使用各种算法来散列文件,包括CRC32.由于我还在家庭中使用其他加密哈希函数Digest
,我认为为它们维护一致的接口会很好.
为了记录,我确实找到digest-crc
了一个完全符合我想要的宝石.问题是,它Zlib
是标准库的一部分,并且具有CRC32的工作实现,我想重用它.此外,它是用C语言编写的,因此它应该提供相对于digest-crc
纯ruby实现的卓越性能.
实施Digest::CRC32
实际上是在第一次看很简单:
%w(digest zlib).each { |f| require f }
class Digest::CRC32 < Digest::Class
include Digest::Instance
def update(str)
@crc32 = Zlib.crc32(str, @crc32)
end
def initialize; reset; end
def reset; @crc32 = 0; end
def finish; @crc32.to_s; end
end
Run Code Online (Sandbox Code Playgroud)
一切看起来都正确:
crc32 = File.open('Rakefile') { |f| Zlib.crc32 f.read }
digest = Digest::CRC32.file('Rakefile').digest!.to_i
crc32 == digest
=> true
Run Code Online (Sandbox Code Playgroud)
不幸的是,并非一切正常:
Digest::CRC32.file('Rakefile').hexdigest!
=> "313635393830353832"
# What I actually expected was:
Digest::CRC32.file('Rakefile').digest!.to_i.to_s(16)
=> "9e4a9a6"
Run Code Online (Sandbox Code Playgroud)
hexdigest
基本上返回 …
当视口小于或等于641px时,我试图将类添加到我的侧边栏,我必须观察该窗口的宽度
$scope.$watch(function(){
return $window.innerWidth;
}, function(value) {
if (value <= 641) {
logger.info('!!!less than 641');
vm.singleColumn = true;
};
});
Run Code Online (Sandbox Code Playgroud)
它会在第一次加载时登录,但是当我调整大小时,我必须在它再次触发之前进行一些点击.例如,我调整了大小,然后点击了具有ng-click行为的项目,那是唯一一次,它再次记录.
我已经阅读了一些问题,这可能是由于$ digest和$ apply?
有人可以解释我的困惑.
我的Epson TM-T88V-i收据打印机尝试从服务器URL获取XML数据,该服务器URL需要打印机通过HTTP摘要进行身份验证.(此Epson功能称为" 服务器直接打印 ")
从打印机的Web控制台,我能够向服务器发送测试请求,但HTTP摘要认证失败.如果让打印机尝试在服务器上进行身份验证,也会发生同样的情况.
如果我尝试通过浏览器访问URL,则会出现HTTP摘要用户名+密码框,如果我输入凭据,XML将按预期显示在浏览器中.这表明服务器端的HTTP摘要机制设置正确(我使用的是PHP框架Symfony 2.8).
在服务器端,我看到以下日志信息:
步骤1
[2016-04-03 16:33:01] security.INFO:抛出了AuthenticationException; 重定向到身份验证入口点.{"exception":"[object](Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code:0):在TokenStorage中找不到令牌.在/home/.../src/Symfony/Component/安全/ HTTP /防火墙/ AccessListener.php:53)"}
步骤2
[2016-04-03 16:33:01] security.DEBUG:调用认证入口点.
步骤3
[2016-04-03 16:33:01] security.DEBUG:从用户代理收到的摘要授权标头.{"header":"username = \"printer \",realm = \"example \",nonce = \"MTQ1OTk5Mzk4MS40NjQ3OmI0OTVmN2ZkZTlhYmE1NmNjNDIxNmIxMWU0OGVmYjUz \",uri = \"/ export \",cnonce = \"MDAxNjM0 \",nc = 00000001 ,qop = \"auth \",response = \" c6ad88607624efd17f7de602f6ee9def \""}
步骤4
[2016-04-03 16:33:01] security.DEBUG:来自DigestAuth的意外响应; 标题返回明文密码? {"expected":" 741bff6abed513b6948c26eae529b6b6 ","已收到":" c6ad88607624efd17f7de602f6ee9def "}
步骤5
[2016-04-03 16:33:01] security.INFO:摘要认证失败.{"exception":"[object](Symfony\Component\Security\Core\Exception\BadCredentialsException(code:0):/home/.../src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener的响应不正确.PHP:107)"}
日志文件告诉我们服务器端发生了什么:
在步骤1 + 2中,Epson尝试访问受HTTP摘要保护的服务器URL,服务器发送带有nonce的401"未授权"响应(我们在此日志文件中没有看到此信息)
在步骤3中,Epson发送HTTP摘要客户端授权请求,包括所有必要的数据.所述响应参数包含散列应出其他授权参数来生成
在步骤4中,我的symfony 2.8应用程序说,Epson在步骤3中发送的散列响应参数不是HTTP摘要过程所期望的参数.
最后,步骤5显示HTTP摘要认证失败.
据我所知,摘要认证过程(如维基百科上所述)是正确的,除了Epson不在他的认证请求中计算正确的哈希值. …
正如我的上一个问题(请参阅此处的详细信息),我正在使用
SELECT encode(digest(x::text::bytea, 'sha1'), 'hex') FROM xtmp;
Run Code Online (Sandbox Code Playgroud)
未解决,与原始哈希值不同...也许是带有符号::text
的强制内部表示\n
,因此解决方案将直接转换为bytea
,但这是无效的转换。
其他解决方法也不是解决方案,
SELECT encode(digest( replace(x::text,'\n',E'\n')::bytea, 'sha1' ), 'hex')
FROM xtmp
Run Code Online (Sandbox Code Playgroud)
...我尝试CREATE TABLE btmp (x bytea)
,COPY btmp FROM '/tmp/test.xml' ( FORMAT binary )
但出现错误(“未知的复制文件签名”)。
我开发了一个网络应用程序,用户可以通过输入字段选择多个文件。然后通过以下代码计算 sha-256 校验和。该代码(取自developer.mozilla.org)仅适用于小文件。我还需要更改什么才能处理大文件(例如 1GB+)?
function sha256(buffer){
return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
var value = view.getUint32(i)
// toString(16) will give the hex representation of the number without padding
var stringValue = value.toString(16)
// We use concatenation and slice …
Run Code Online (Sandbox Code Playgroud) 我有一个域,可供一小群私人访问。所以我想通过身份验证控制访问。
该域安装了一组应用程序,每个应用程序都有自己的子域。例如:domain.com、app1.domain.com、app2.domain.com、app3.domain.com
我很想有一个单点登录解决方案,这样他们就不必为每个应用程序进行身份验证。此外,应用程序是用不同的语言(PHP、Python 和 Perl)编写的,因此通过 Apache 模块对用户进行身份验证是理想的。
我是消化身份验证的新手,但这似乎是一个很好的解决方案。我曾经htdigest
创建过我的用户。我已经配置了我的域和子域(见下文)。
如果我转到域或任何子域,它会提示输入用户名和密码。如果我输入正确的用户名和密码,它将对我进行身份验证并加载页面。但是,如果我转到另一个子域,它会要求我再次输入用户名和密码。如果我输入相同的用户名和密码,它将起作用。
所以密码文件没问题,认证也没问题,但问题好像出在AuthDigestDomain
.
我在网上搜索了一个在多个域上使用摘要式身份验证的示例,但找不到解决我问题的具体示例。
我希望这里有人可以提供帮助。我是否将相同的身份验证信息放入每个Directory
? 我应该使用Directory
或Location
或Files
?我错过了什么吗?
提前致谢!
下面是我的 domain.com 的 Apache 配置示例:
<Directory /var/www>
AuthType Digest
AuthName "realm"
AuthDigestAlgorithm MD5
AuthDigestDomain / http://domain.com/ http://app1.domain.com/ http://app2.domain.com/ http://app3.domain.com/
AuthDigestNcCheck Off
AuthDigestNonceLifetime 0
AuthDigestQop auth
AuthDigestProvider file
AuthUserFile /etc/apache2/.htpasswd-digest
AuthGroupFile /dev/null
Require valid-user
</Directory>
Run Code Online (Sandbox Code Playgroud)
这是 app1.domain.com 的示例:
<Directory /var/lib/app1>
AuthType Digest
AuthName "realm"
AuthDigestAlgorithm MD5
AuthDigestDomain / http://domain.com/ http://app1.domain.com/ http://app2.domain.com/ http://app3.domain.com/
AuthDigestNcCheck Off
AuthDigestNonceLifetime …
Run Code Online (Sandbox Code Playgroud) 据我所知,我有以下功能:
如果用户转到另一个页面,它将收到“401 访问被拒绝”,因为该请求中没有身份验证标头。这就是问题所在。
以 dockerhub 上托管的以下存储库为例:\n https://hub.docker.com/r/frolvlad/alpine-miniconda3 \n
\n
\n
\n执行以下命令以通过摘要提取映像:
docker pull frolvlad/alpine-miniconda3:python3.7@sha256:9bc9c096713a6e47ca1b4a0d354ea3f2a1f67669c9a2456352d28481a6ce2fbe\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n根据docker 文档,通过摘要提取图像具有以下属性:
\n\n\n使用此功能\xe2\x80\x9cpins\xe2\x80\x9d将图像及时转换为特定版本
\n
据我了解,在任何时候使用该摘要提取的 docker 映像都是不可变的。\n
尽管它不会对其中的可变或看似可变的引用进行评论。\n
\n
\n最重要的是docker 的第一行文件读取
FROM frolvlad/alpine-glibc:alpine-3.9\n
Run Code Online (Sandbox Code Playgroud)\n\n根据我的阅读,我认为如果作者更改了 dockerfile 中的第一行并推送(即使它是相同的标签),我将不会受到影响,因为我指向图像摘要。然而,\n由于作者引用了 dockerfile 中的标签,而不是摘要,我如何确认使用什么 dockerfile/基本映像来构建其映像?因为看起来仅仅分析frolvlad/alpine-glibc:alpine-3.9
dockerfile 是不够的,因为它在创建映像时可能会有所不同。
digest ×10
javascript ×2
ruby ×2
angularjs ×1
apache ×1
cryptography ×1
docker ×1
dockerfile ×1
epson ×1
hash ×1
hashlib ×1
jquery ×1
postgresql ×1
python ×1
sha512 ×1
subdomain ×1
symfony ×1