How to decode Hex using ASN1 decoder using OpenSSL - ios

I have hex value which contain email id as UTF8 string like :
30440C17726F6869746B616C6538353231407961686F6F2E636F6D180F32303232303932393131303234395A0C05656D61696C060B6086480186FD1E0101020702020C000C00
How do I decode and get email id using OpenSSL in iOS objective-C / C ?
I can able to decode using online Hex to ANS1 decoder
Output come as:
SEQUENCE {
UTF8String 'rohitkale8521#yahoo.com'
GeneralizedTime '20220929110249Z'
UTF8String 'email'
OBJECTIDENTIFIER 2.16.840.1.114334.1.1.2.7
INTEGER 0x0C00 (3072 decimal)
UTF8String ''
}

Related

Flutter - Remove escape sequence in dart

To decode API response string to JSON, json.decode() works fine.
This will parse a JSON string similar to
{ "Response" : {"Responsecode" : "1" , "Response" : "Success"}}
But in my case, the response comes in the serialized form like:
{\"Response\" : {\"Responsecode\" : \"0\" , \"Response\" : \"Success\"}}
json.decode() won’t work.
In Java, I used StringEscapeUtils.unescapeJson() for the same problem.
I searched for Dart but couldn’t find how to unescape characters in a string.
Edit:
Suppose, the value of key data is abc"de
So, its corresponding JSON would be {"data":"abc\"de"}
And hence during serialization, this json string is escaped to give {\"data\":\"abc\\\"de\"} as the response, which is sent by the API.
So, my intention is to remove the escape sequences, so that I can get the string {"data":"abc\"de"}, which would later be decoded using json.decode(). Removing the escape sequences was done using StringEscapeUtils.unescapeJson() in java.
json.decode can decode single strings too, so you should be able to just call it twice. The first time it'll return you a string (where the escape characters have been decoded) and the second time it'll decode that string into the map:
import 'dart:convert';
void main() {
var a = r'''"{\"Response\" : {\"Responsecode\" : \"0\" , \"Response\" : \"Success\"}}"''';
var b = json.decode(json.decode(a));
print(b['Response']['Responsecode']); // 0
print(b['Response']['Response']); // Success
}

Get Query string as it is passed

I'm new to Go. My question is how to get URL encoded string on stdout.
Below is the URL string I am using to hit an api.
schooltubeapi/v1/channeldetails?channelName=long%20division%20.
Below is the code that I am using to get RawQuery
url1 := ChannelName
u, _ := url.Parse(url1)
log.Println(u)
u.RawQuery = u.Query().Encode()
log.Println(u)
[Output]
long division
[Expected]
long%20division%20
I have searched alot But cannot found a similar problem with a solution.
For url encoded string use URL struct of url package to get RawQuery as passed in the URI:
package main
import (
"fmt"
"net/url"
)
func main() {
stringValue := "long division "
t := &url.URL{Path: stringValue}
encodedString := t.String()
fmt.Println(encodedString)
}
Playground Example
In Golang spec for URL. It is stated:-
that the Path field is stored in decoded form: /%47%6f%2f becomes
/Go/. A consequence is that it is impossible to tell which slashes in
the Path were slashes in the raw URL and which were %2f. This
distinction is rarely important, but when it is, code must not use
Path directly. The Parse function sets both Path and RawPath in the
URL it returns, and URL's String method uses RawPath if it is a valid
encoding of Path, by calling the EscapedPath method.
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
Path string // path (relative paths may omit leading slash)
RawPath string // encoded path hint (see EscapedPath method)
ForceQuery bool // append a query ('?') even if RawQuery is empty
RawQuery string // encoded query values, without '?'
Fragment string // fragment for references, without '#'
}
For more information Check Golang spec for URL

decode msgpack in redis lua

public class MsgPackInRedis {
private String ip;
private int port;
private String session;
private String protocol;
}
MsgPackInRedis msgPackStringInRedis = new MsgPackInRedis();
I encode a java object msgPackStringInRedis of class MsgPackInRedis with msgpack, then store in redis.
And I want to decode that in lua, which runs in redis, how can I get "session" ?
Can I do like this below, get session by index 3?
local msgPackObject = cmsgpack.unpack(msgPackStringInRedis)
local session = msgPackObject[3]
MessagePack is an encoding - think non-easily-readable JSON. In fact, this website does a back and forth translation between the two: http://kawanet.github.io/msgpack-lite/
Feeding your (0x94 0xc0 0x00 0xa4 0x41 0x42 0x43 0x44 0xc0) to the above website, you can see the JSON representation which looks like:
[
null,
0,
"ABCD",
null
]
You can test that in Redis' Lua as well, e.g. (note that Lua 5.1 accepts decimal byte representation, hence the different representation of the same payload in the example):
$ redis-cli EVAL "return(cmsgpack.unpack('\148\192\00\164\65\66\67\68\192')[3])" 0
"ABCD"
So frankly, I see no issue with your code. What is the problem that you are experiencing exactly?
Assuming that your MessagePack-ed data is stored in the String key called foo, this would do your bidding:
EVAL "return cmsgpack.unpack(redis.call('GET', KEYS[1]))" 1 foo
Note : the above assumes that the data is serialized as arrays. Returning an object will not work as Redis' protocol doesn't support that.

.NET RSAKeyValue base64 private key to a single base64 private key

I am supplied the following RSA private key in the format
<RSAKeyValue>
<Modulus>XXXXXXXX</Modulus>
<Exponent>XXXXXXXX</Exponent>
<P>XXXXXXXX</P>
<Q>XXXXXXXX</Q>
<DP>XXXXXXXX</DP>
<DQ>XXXXXXXX</DQ>
<InverseQ>XXXXXXXXXX/InverseQ>
<D>XXXXXXXX</D>
</RSAKeyValue>
The XXXX are in Base64 format.
I want to know how to combine it all the XXXXXX bits to a single Base64 string.
With this single Base64 string i do the following:
1. Feed it to a TMemorStream
2. use Indy's TIdDecoderMIME class to decode Base64 from the MemoryStream
3. The decoded MemoryStream is then feed into CryptDecrypt function from wcrypt2.pas (a delphi wrapper of Microsoft's Cryptographic API) from Jedi
I know the solution for public key in the same format
<RSAKeyValue>
<Modulus>xqiYKv0umaLdmrKPyBfYmAfzZYVsvsOJyS4c1lBPjqpn7zh+XyxPXK7MxJkAlenQJM33M+ZYfmlPLya7JWXXTPviylEEtlmul9GshpX2caxWu2YO9vNIHRZYYau4ccbkm95iMyJi8KN2ANtqDwiJv55vcXZDqjPSDE4ap49xmog==</Modulus>
<Exponent>AAQC</Exponent>
</RSAKeyValue>
The solution is to add "BgIAAACkAABSU0ExAAQAAAE" + Exponent + Modulus
The result is:
BgIAAACkAABSU0ExAAQAAAEAAQCxqiYKv0umaLdmrKPyBfYmAfzZYVsvsOJyS4c1lBPjqpn7zh+XyxPXK7MxJkAlenQJM33M+ZYfmlPLya7JWXXTPviylEEtlmul9GshpX2caxWu2YO9vNIHRZYYau4ccbkm95iMyJi8KN2ANtqDwiJv55vcXZDqjPSDE4ap49xmog==
With the private key how do we combine it? I know it starts off like this:
"BwIAAACkAABSU0ExAAQAAAE" + Exponent + Modulus + ???????
The XXXX in the RSAKeyValue XML are in base64, just that i do not want to expose the details there. I want to know how do i combine all the XXXX base64 codes into a single base64 private key.
I suspect that this means that you are performing the base64 encoding line by line. It's much simpler to perform the encoding on the entire file.
For example you might do this as follows:
Load the file into a TStringList.
Extract a single string representing the file using the Text property of the string list.
Base64 encode that string.
Send it over the wire.
At the receiving end, decode the string.
Assign the string to the Text property of a string list.

How to GetBytes() in C# with UTF8 encoding with BOM?

I'm having a problem with UTF8 encoding in my asp.net mvc 2 application in C#. I'm trying let user download a simple text file from a string. I am trying to get bytes array with the following line:
var x = Encoding.UTF8.GetBytes(csvString);
but when I return it for download using:
return File(x, ..., ...);
I get a file which is without BOM so I don't get Croatian characters shown up correctly. This is because my bytes array does not include BOM after encoding. I triend inserting those bytes manually and then it shows up correctly, but that's not the best way to do it.
I also tried creating UTF8Encoding class instance and passing a boolean value (true) to its constructor to include BOM, but it doesn't work either.
Anyone has a solution? Thanks!
Try like this:
public ActionResult Download()
{
var data = Encoding.UTF8.GetBytes("some data");
var result = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
return File(result, "application/csv", "foo.csv");
}
The reason is that the UTF8Encoding constructor that takes a boolean parameter doesn't do what you would expect:
byte[] bytes = new UTF8Encoding(true).GetBytes("a");
The resulting array would contain a single byte with the value of 97. There's no BOM because UTF8 doesn't require a BOM.
I created a simple extension to convert any string in any encoding to its representation of byte array when it is written to a file or stream:
public static class StreamExtensions
{
public static byte[] ToBytes(this string value, Encoding encoding)
{
using (var stream = new MemoryStream())
using (var sw = new StreamWriter(stream, encoding))
{
sw.Write(value);
sw.Flush();
return stream.ToArray();
}
}
}
Usage:
stringValue.ToBytes(Encoding.UTF8)
This will work also for other encodings like UTF-16 which requires the BOM.
UTF-8 does not require a BOM, because it is a sequence of 1-byte words. UTF-8 = UTF-8BE = UTF-8LE.
In contrast, UTF-16 requires a BOM at the beginning of the stream to identify whether the remainder of the stream is UTF-16BE or UTF-16LE, because UTF-16 is a sequence of 2-byte words and the BOM identifies whether the bytes in the words are BE or LE.
The problem does not lie with the Encoding.UTF8 class. The problem lies with whatever program you are using to view the files.
Remember that .NET strings are all unicode while there stay in memory, so if you can see your csvString correctly with the debugger the problem is writing the file.
In my opinion you should return a FileResult with the same encoding that the files. Try setting the returning File encoding,

Resources