我的代码在Android上运行良好.当我用JRE 1.6将它移植到我的Windows 64位机器时,代码不起作用.
当我运行以下代码行时:
final MessageDigest digest = MessageDigest.getInstance("SHA256")
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
java.security.NoSuchAlgorithmException:SHA256 MessageDigest在java.security.MessageDigest.getInstance(未知来源)的java.security.Security.getImpl(未知来源)的sun.security.jca.GetInstance.getInstance(未知来源)中不可用
我在Internet上发现人们声称可以将SHA256与Sun JRE附带的标准加密提供程序一起使用,人们说我需要使用其他提供程序,例如Bouncy Castle.
我宁愿不使用其他提供商.它可以使它工作吗?
在密码学等方面,我是一个全新的人.我不(也不想)知道SHA256和RSA的细节.我"知道"他们做了什么,而不是他们是怎么做的,现在这已经足够了.
我想知道什么是"SHA256withRSA"算法(如果你可以称之为),实际上是以什么顺序进行的.例如,它是否使用SHA256对数据进行哈希处理,然后使用RSA对其进行加密,反之亦然,还是其他什么?
我问的原因是因为我想做java相当于:
Signature.getInstance("SHA256withRSA")
signature.initSign(privateKey); //privateKey == a key extracted from a .p12 file
Run Code Online (Sandbox Code Playgroud)
在iOS上的Objective-C中.而我似乎无法找到任何完全符合这一要求的东西,因此我问,我可以只散列数据(SHA256)然后加密它(RSA)(反之亦然)并获得相同的行为吗?
做这种事情的建议解决方案是什么?
谢谢!
编辑:我没有提到我使用通过执行以下操作获得的私钥来签署数据:
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(new FileInputStream(new File(filename)), password.toCharArray());
PrivateKey privateKey = (PrivateKey)keystore.getKey(alias, password.toCharArray());
Run Code Online (Sandbox Code Playgroud)
其中filename是例如:"/ somewhere/mykey.p12".
如何从命令行检查我的SSL证书是否使用SHA1或SHA2?
是的,我这类似于此,但我需要一个cli工具,我想了解它是如何完成的.
我有这个PHP代码:
$password = sha256($_POST['password']);
Run Code Online (Sandbox Code Playgroud)
但是当我运行这段代码时,它说:
Fatal error: Call to undefined function sha256() in .... on line ...ix it as
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题,我必须做些什么才能解决这个问题,因为我知道sha256存在.
我也尝试过:
$password = sha256(trim($_POST['password']));
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
我一直在努力研究SHA-256的工作原理.我一直在为其他算法做的一件事是我已经为算法制定了一种逐步的伪代码函数.
我试过为SHA256做同样的事情,但到目前为止我遇到了很多麻烦.
我试图弄清楚维基百科图如何工作,但除了解释函数的文本部分,我不确定我是否正确.
这是我到目前为止所拥有的:
Input is an array 8 items long where each item is 32 bits.
Output is an array 8 items long where each item is 32 bits.
Calculate all the function boxes and store those values.
|I'll refer to them by function name
Store input, right shifted by 32 bits, into output.
| At this point, in the out array, E is the wrong value and A is empty
Store the function boxes.
| now we need …Run Code Online (Sandbox Code Playgroud) 我们有一段代码创建了一个SigningCredentials对象,用于使用SHA256算法对xml文档进行签名.它完美适用于.NET 3.5.但是,当我们将代码库升级到.NET 4.5时,它会停止工作.相同的代码,相同的证书!我花了好几个小时在互联网上调试和搜索,没有任何运气.
谁能告诉我这里的问题是什么?先感谢您.
创建SigningCredentials的代码:
public SigningCredentials CreateSigningCredentials(X509Certificate2 cert)
{
var ski = new SecurityKeyIdentifier(new X509RawDataKeyIdentifierClause(cert));
return new SigningCredentials(new X509AsymmetricSecurityKey(cert), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", "http://www.w3.org/2001/04/xmlenc#sha256", ski);
}
Run Code Online (Sandbox Code Playgroud)
例外:
[CryptographicException: Invalid algorithm specified.
]
System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature) +0
System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash) +118
System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash) +334
System.Security.Cryptography.RSAPKCS1SignatureFormatter.CreateSignature(Byte[] rgbHash) +321
System.IdentityModel.SignedXml.ComputeSignature(HashAlgorithm hash, AsymmetricSignatureFormatter formatter, String signatureMethod) +323
System.IdentityModel.SignedXml.ComputeSignature(SecurityKey signingKey) +690
System.IdentityModel.EnvelopedSignatureWriter.ComputeSignature() +338
System.IdentityModel.EnvelopedSignatureWriter.OnEndRootElement() …Run Code Online (Sandbox Code Playgroud) 当我使用此代码创建字符串的sha256时
unsigned char hashedChars[32];
NSString *inputString;
inputString = [NSString stringWithFormat:@"hello"];
NSData * inputData = [inputString dataUsingEncoding:NSUTF8StringEncoding];
CC_SHA256(inputData.bytes, inputData.length, hashedChars);
Run Code Online (Sandbox Code Playgroud)
它正确地返回哈希,但是我需要插入一个类似于\ x00\x25\x53的字符串,在这种情况下,该函数返回一个空字符串的sha256,因为指定的编码不能用于转换接收器.
现在,我的问题是:如何插入此特殊字符以生成正确的哈希?谢谢
我想读一个密码文件.然后我尝试计算每个密码的哈希值,并将其与我已经拥有的哈希值进行比较,以确定我是否发现了密码.但是我不断得到的错误消息是"TypeError:必须在散列之前对Unicode对象进行编码".这是我的代码:
from hashlib import sha256
with open('words','r') as f:
for line in f:
hashedWord = sha256(line.rstrip()).hexdigest()
if hashedWord == 'ca52258a43795ab5c89513f9984b8f3d3d0aa61fb7792ecefe8d90010ee39f2':
print(line + "is one of the words!")
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙并提供解释吗?
我试图在python中编写一个简单的工作证明nonce-finder.
def proof_of_work(b, nBytes):
nonce = 0
# while the first nBytes of hash(b + nonce) are not 0
while sha256(b + uint2bytes(nonce))[:nBytes] != bytes(nBytes):
nonce = nonce + 1
return nonce
Run Code Online (Sandbox Code Playgroud)
现在我尝试进行多处理,因此它可以使用所有CPU内核并更快地找到nonce.我的想法是multiprocessing.Pool多次使用和执行函数proof_of_work,传递两个参数num_of_cpus_running,this_cpu_id如下所示:
def proof_of_work(b, nBytes, num_of_cpus_running, this_cpu_id):
nonce = this_cpu_id
while sha256(b + uint2bytes(nonce))[:nBytes] != bytes(nBytes):
nonce = nonce + num_of_cpus_running
return nonce
Run Code Online (Sandbox Code Playgroud)
所以,如果有4个核心,每个核心将计算这样的随机数:
core 0: 0, 4, 8, 16, 32 ...
core 1: 1, 5, 9, 17, 33 ...
core 2: 2, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在WebAssembly中实现JWT令牌(仅编码),目标是拥有一个非常轻量级的 wasm模块.作为Web开发人员,我的C知识是有限的.现在我已经实现了以下功能(从JS移植)来编码url-safe Base64编码器,它完美地工作.
char _keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
char ret_val[200];
char* encode (char *data){
int len = strlen(data);
int i = 0;
int j = 0;
while(i<len){
char chr1 = data[i++];
int chr2Out = (i > len - 1)? 1:0;
char chr2 = data[i++];
int chr3Out = (i > len - 1)? 1:0;;
char chr3 = data[i++];
char enc1 = chr1 >> 2;
char enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
char enc3 = ((chr2 & …Run Code Online (Sandbox Code Playgroud) sha256 ×10
cryptography ×5
java ×2
python ×2
sha ×2
.net ×1
c ×1
certificate ×1
emscripten ×1
hash ×1
ios ×1
iphone ×1
jwt ×1
nonce ×1
objective-c ×1
openssl ×1
php ×1
pseudocode ×1
rsa ×1
sha1 ×1
signing ×1
ssl ×1
trim ×1
undefined ×1
webassembly ×1
wif ×1
xcode ×1