I use this code for sha1 and base64Encode in objective-c.But I get a different result for android and ios. So I need to translate JAVA code to objective-c.
+ (NSString *)sha1:(NSString *)str { const char *cStr = [str UTF8String]; unsigned char result[CC_SHA1_DIGEST_LENGTH]; CC_SHA1(cStr, strlen(cStr), result); NSString *s = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15], result[16], result[17], result[18], result[19] ]; return s;}[[str dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString];
I need to use this JAVA code in the objective-c project. Please help me to translate it.
public static String sha1(String convertString) { MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-1"); md.update(convertString.getBytes("iso-8859-1"), 0, convertString.length()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } byte[] bytes = md.digest(); return Base64.encodeToString(bytes, Base64.NO_WRAP);}
I don't want to calculate a file's checksum, just to know if a given string is a valid checksum
This question already has an answer here:
I have to write method like this:
boolean isHash(String str){ ...}
Method should return true if input string is md5
hash or sha1
hash or sha256
hash.
Is it possible to implement such method ?
[]byte
to string raises an error.string([]byte[:n])
raises an error too.By the way, for example, sha1 value to string for filename.Does it need utf-8 or any other encoding set explicitly? Thanks!
We are upgrading our website from ASP.NET 4.61 to 4.8 and running into the following issue with our certificate. https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/retargeting/4.5.2-4.7.1#default-signedxml-and-signedxms-algorithms-changed-to-sha256
Our cert is SHA2 but the SignedXML and SignedXMS algorithm is SHA1 in the cert. I would like to get our cert re-issued with SignedXML and SignedXMS algorithms as SHA256, which is the default for .NET 4.71 and up.
*Question is, would the re-issued cert work in our current production environment with .NET 4.61 before the next release. Or would we have to install the new cert with the release?
If my understanding is correct, the algorithm is set in the certificate for the crypto service provider and would use the SHA256 algorithm from the re-issued certificate without modifications?
I do see in the registry under .../SCHANNEL/Hashes/SHA256 is enabled.
Дом - Карта на сайта - Уединение - Звена - Copyright © 2019 Cortex IT Ltd : Контакт : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Уединение for details). You will only see this message once.