I am working on an iPhone application that requires Base64 decoding using HmacSHA1 algorithm. Can anyone help me doing the objective-C equivalent of the given Java code:
SecretKeykey = new SecretKeySpec(com.sinotar.algorithm.Base64.decode(
"vNQKX3C1wD/KprnnOcdRwM80YIn5bo47w9VdTlDpCB8="), "HmacSHA1");
Thanks matthijz, But it has nothing to do with HmacSHA1. The solution I am looking for is something that does the equivalent of the Java code:
SecretKey key = null;
try { key = new SecretKeySpec(com.sinotar.algorithm.Base64.decode("vNQKX3C1wD/KprnnOcdRwM80YIn5bo47w9VdTlDpCB8="),
"HmacSHA1");
}
Any help is appreciated.
Check out Matt Gallagher's article on Base64 encoding - it has downloadable code at the end. http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
The code you quote appears to be taking a base64 value, converting it to binary, and using it to set the key for an HMACSHA1 algorithm. The two steps are conceptually separate.
Here is the page for HMAC_SHA1 on Mac -- I haven't found the equivalent for iPhone, but I would assume it exists.
Related
I've been searching through the Internet and I don't seem to find a way of converting a simple string into a Base64 string in MIT App Inventor 2.
All I can find are extensions to convert images to Base64, but not strings. Is there a way that I am not realizing?
You might want to try the tools extension and its Base64Encode method:
I am using OWASP encoder to encode my strings, but the string is not decoding in JSP pages. It is showing as it is like encoded string, e.g. My original String is l&t.com. After encoding, the string is "l'&';t.com", but again it should decode in JSP which is not happening. Can any one please suggest. I am using utf-8 meta tag also in JSP .
Any help much much appreciated .Thanks
I found the solution for this. We need to add escapeXml = false for the respective value, then this will be resolved.
I am trying to encode PGWRecord CDR using ASN.1 notation, starting on page 89 in this 3GPP TS Document
I've been looking for awhile for examples how I can do this, but to no avail. Are there any examples that can show me how to do this using Bouncy Castle? Or is there a better alternative than Bouncy Castle to encode this CDR?
Step by step instructions on how I can do this would be very nice!
Any help would be very appreciated. Thanks all!
Ya, just two months back i have worked on Bouncy castle to decode CDRS which of 3GPP stranded encoded file. Currently i am good in decoding and if any issues on decoding i can give more example and i can solve it easily solve it.
But for your question i can suggest some points and if you have any question pleas add comment. It not only help for you it can help for new bees who start with encode / decode process.
a) You did right API choice (Bouncy Castle) for encoding CDRS files
b) You can go for paid version of encode / decode APIs but it is too expansive
c) I have found 3 paid APIs which gives good and expected results, those are
1) [OSS Nokalva][1]
2) Obj-Sys
3) unigone
d) For me Bouncy castle gave 100% result then paid APIs even though they work well and good. If you want to use Bouncy castle then you need to put some more effort to work on encoding, So Bouncy castle is an API which support basic and some advanced parser, to do any encoding / decoding you need to write the java classes as per your ASN.1 syntax specification and so on.. I can write the steps but it will be too long so end of this answer i am giving you a link which explain it better. click on this link and download bcprov-jdk15on-154.tar.gz file.
e) Unzip the package you downloaded and go to bcprov-jdk15on-154\bcprov-jdk15on-154\src\org\bouncycastle\asn1\test you will find N number of examples to encode/decode CDRs according to the ASN.1 syntax specification
f) If you want to understand with very simple example then go through this link you can easily do your job
Still if you find difficult to understand then write a comment i will try to help my best.
Try to look at BinaryNotes. You have ASN.1 definition of what you are trying to encode. BinaryNotes will generate classes for encoding/decoding objects to/from ASN.1.
BinaryNotes works with xlst transformations to generate classes. You could modify the transformations in a way that it will use bouncy classes form encoding/decoding.
I guess that the encoding of GPRSRecord CHOICE would be something like that below.Be careful to tag values and conversion from string view to hex and BCD packing for IMSI and GSNAddress value :
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new BERTaggedObject(true, 0, new ASN1Integer(18))); //e.g. sgsnPDPRecord (18)
v.add(new BERTaggedObject(true, 3, new BEROctetString(Hex.decode("490154203237518")); //IMSI. String to BCD bytes conversion needed
v.add(new BERTaggedObject(true, 4, new BERTaggedObject(true, 0, new DEROctetString(Hex.decode("994507776655"))))); // GSNAddress
v.add(new BERTaggedObject(true, 5, new BEROctetString(Hex.decode("00DB")))); //ChargingID
byte[] encoded = BERTaggedObject.getInstance(new BERTaggedObject(true, 78, new BERSet(v))).getEncoded(); //SGWRecord
I am using libxml for parsing the xml. I have referred the XMLPerformance example by apple.
Following is the part of xml document which is causing a problem as it contain the " " string. i cannot just replace this " " with any other string is i am getting data in didReceiveData delegate method and i am parsing that data.
Is there any solution to resolve this issue which is coming because of special character?
<ParentTag>
<AUTHOR>Actavis"Totowa "LLC</AUTHOR>
<SPL_INACTIVE_ING>lactose"monohydrate"/"magnesium"stearate"/"starch"pregelatinized"/"talc</SPL_INACTIVE_ING>
</ParentTag>
Any help will be appreciated.
Thanks in advance
To make sure your XML is well format, you can test you XML first with any online XML validator and then later you should parse that.
How do I do the equivalent of the following C++ code in go?
RSA *key = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL);
std::vector<CK_BYTE> out(128);
RSA_private_encrypt(in.size(), &in[0], &out[0], key, RSA_PKCS1_PADDING)
I've looked at the Go rsa package. It looks like EncryptPKCS1v15() may be the equivalent of RSA_private_encrypt(). But I don't see how to create a PrivateKey object other than with GenerateKey(), which (one can confirm by looking at the source) generates one using random prime numbers.
Do I need to figure out how to decode a PEM file so pull out the PrivateKey fields' values?
Update: The equivalent to the above C++ code in Python is:
from M2Crypto import RSA
rsa_private_key = RSA.load_key('privkey.pem')
encrypted = rsa_private_key.private_encrypt(digest, RSA.pkcs1_padding)
Is there an existing equivalent in Go?
I think you may be looking for crypto/tls, not crypto/rsa.
I'm not 100% sure what you're trying to do here, but the tls package does have some functionality for reading PEM files.
The equivalent function appears to be SignPKCS1v15. The function ParsePKCS1PrivateKey in the crypto/x509 package appears to be the closest to what you need to read in your existing private key, but I'm not sure the PEM format is exactly compatible, which it must be for this to work.