在Maven存储库中是否有一个简单的Java库,它将为流行的哈希函数(如MD5,SHA1,SHA256和SHA512)提供简单的单线程哈希方法?我真的很讨厌必须重新发明轮子才能做到这一点.
是否可以使用用户的视频卡在浏览器中计算sha256哈希值,例如.使用WebGL或Flash?
我担心这就是要问的问题,但如果需要更详细的说明,请不要犹豫,在评论中告诉我.
谢谢.
我正在尝试使用OpenSSL/libcrypto编写一个C函数来计算文件的SHA256总和.我在我的基础上亚当拉默的C++示例代码在这里.
这是我的代码:
int main (int argc, char** argv)
{
char calc_hash[65];
calc_sha256("file.txt", calc_hash);
}
int calc_sha256 (char* path, char output[65])
{
FILE* file = fopen(path, "rb");
if(!file) return -1;
char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
const int bufSize = 32768;
char* buffer = malloc(bufSize);
int bytesRead = 0;
if(!buffer) return -1;
while((bytesRead = fread(buffer, 1, bufSize, file)))
{
SHA256_Update(&sha256, buffer, bytesRead);
}
SHA256_Final(hash, &sha256);
sha256_hash_string(hash, output);
fclose(file);
free(buffer);
return 0;
}
void sha256_hash_string (char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65])
{
int …Run Code Online (Sandbox Code Playgroud) 根据我使用HMAC SHA256阅读的各种文档,我已经理解:
H(K XOR opad,H(K XOR ipad,text))其中H在我的情况下是SHA256.
但是,SHA256输入只有一个参数,即消息.而H(K,text)有两个输入.那么如何计算H(k,文本)?
我应首先使用k对文本进行编码,然后使用H(encoded_text),其中encoded_text将用作消息?
谢谢
我需要在JAVA中对我的XML消息进行数字签名:生成的XML签名应具有以下格式:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<DigestValue>DsP5NLca+plhp9tZvGwykfb2whQYt3CQ5sbsVd9Q9aE=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
LrfE0po3YPvVxB/m77iBWWiR07Ghiuhuj7tO2C2LKqZK2cLrAiidt+3tjbJ3m16quCFxfh7bmjRtJsGi7a3HKtK
qY4auqrjNB62AtYrxvm+7Qd/cRacom4e3M9uF9JD1zTfoGun9w4WDfDrDaoZ+ZwUgNtf6sTYO5Ctcj5sYcD0=
</SignatureValue>
<KeyInfo>
<KeyName>7D665C81ABBE1A7D0E525BFC171F04D276F07BF2</KeyName>
</KeyInfo>
</Signature>
Run Code Online (Sandbox Code Playgroud)
谁能提供一些代码帮助?
编辑:
我想出了这段代码:
private static Document sign(Document doc) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException,
FileNotFoundException, TransformerException {
String providerName = System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", (Provider) Class.forName(providerName).newInstance());
Reference ref = fac.newReference("", fac.newDigestMethod(DigestMethod.SHA256, null));
// Create the SignedInfo
SignedInfo si = fac.newSignedInfo(
fac.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null),
fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null), …Run Code Online (Sandbox Code Playgroud) 我正在做一些密码学实验.现在我有接收器的公钥,我想加密一些数据并传递给接收器.
我想使用RSAES-OAEP算法.SHA-256作为哈希函数,MGF1作为掩码生成函数.
我想用openssl做这个.我找到了一个RSA_public_encrypt()具有此功能的函数,我们可以指定填充.其中一个填充选项是
RSA_PKCS1_OAEP_PADDING
在PKCS#1 v2.0中使用SHA-1,MGF1定义的EME-OAEP.
他们正在使用sha-1.
我想重新配置函数使用SHA256作为哈希函数和MGF1作为哈希函数.我该怎么做 ?
我用AES 256密钥加密字节有问题.我已经安装了这个政策.这就是我所做的:
但我仍然收到以下代码的错误消息:
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(256);
SecretKey secretKey = keyGenerator.generateKey();
Cipher decryption = Cipher.getInstance("AES/CBC/PKCS5PADDING");
decryption.init(Cipher.DECRYPT_MODE, secretKey,
new IvParameterSpec(secretKey.getEncoded())); // <-- Illegal key size
Run Code Online (Sandbox Code Playgroud)
我的Java版本:
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
Run Code Online (Sandbox Code Playgroud)
我需要做什么,使用256 AES加密?
我们需要使用全新的证书更新我们的Azure云服务.
我给出的那个指定sha256作为签名哈希算法.
我们之前有一个sha1.
当我尝试更新和部署Azure部署时,我得到的错误表明thumprint无效.
错误8 XML规范无效:'thumbprint'属性无效 - 根据其数据类型' http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration:ThumbprintType,值'REDACTED'无效' - 模式约束失败.
在ServiceConfiguration.Cloud.cscfg文件中,XML如下所示:
<Certificates>
<Certificate name="cert" thumbprint="REDACTED" thumbprintAlgorithm="sha1" />
</Certificates>
Run Code Online (Sandbox Code Playgroud)
与thumprint属性squiggly排列为上面的错误.
我尝试过thumbprintAlgorithm = 256,但这不起作用,大概不是一个有效的值.
它需要是sha1吗?Azure可以支持sha256吗?
编辑:我在服务定义模式中找到以下内容,表明允许sha256:
<xs:attribute name="thumbprintAlgorithm" type="ThumbprintAlgorithmTypes" use="required">
<xs:annotation>
<xs:documentation>
The hash algorithm that generates a digest of data (or thumbprint)
for digital signatures such as MD5, SHA1, SHA256. This is different than
the algorithm used in creating the signature inside the certificate.
</xs:documentation>
</xs:annotation>
</xs:attribute>
Run Code Online (Sandbox Code Playgroud)
但是,架构允许的唯一类型值是sha1,如下所示:
<xs:simpleType name="ThumbprintAlgorithmTypes">
<xs:restriction base="xs:string">
<xs:enumeration value="sha1">
<xs:annotation>
<xs:documentation>
Algorithm currently used …Run Code Online (Sandbox Code Playgroud) 以这个哈希为例:
ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
Run Code Online (Sandbox Code Playgroud)
对于我的目的来说太长了,所以我打算使用其中的一小部分,例如:
ba7816bf8f01
ba7816bf
Run Code Online (Sandbox Code Playgroud)
或者类似的。我的预期用例:
//example.com/video-gallery/灯箱/ ba7816bf8f01
我以为我会将视频的 URL SHA256,使用前几个字符作为临时 ID。我应该从生成的哈希中使用多少个字符,以大大减少冲突的机会?
我从URLs and Hashing by Google 中得到了这个想法。
在 Rust 中,使用sha256 = "1.0.2"(或类似),如何散列二进制文件(即tar.gz存档)?
我正在尝试获取该二进制文件的 sha256。
这不起作用:
fn hash() {
let file = "file.tar.gz";
let computed_hash = sha256::digest_file(std::path::Path::new(file)).unwrap();
computed_hash
}
Run Code Online (Sandbox Code Playgroud)
输出是:
...
Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }
Run Code Online (Sandbox Code Playgroud)