Converting binary blob private key to base64 format - binary

So, I have a private key in binary blob format which looks like some encrypted junk. Now, what should I do in order to transform that into a correct looking private key which is usable by openssl ?
For instance, I want it to be in -----BEGIN PRIVATE KEY----- some base64 -----END PRIVATE KEY----- format.
How is it possible ?

Convert the binary blob to string or base64 decode the whole thing and see what it produces. If it is gibrrish, you would need to see if it is encoded differently or if it is encrypted. If later, you need to decrypt.
It is difficult to provide a concrete answer without having more details on the data format.

Related

How to display Blob /Json data field in Liferay 7.2?

I am using a service builder that is retrieving the form data fine from mysql db. I have a field that has the json data and I tried to map it using object mapper and using com.fasterxml.jackson.databind.ObjectMapper to display the json content. However, the Blob Data is shown as: com.mysql.cj.jdbc.Blob#4ca74f7f
How do I actually get/extract the data from the storing link above? Here is my code snippet:
for (ddmcontent MyTemp : myList) {
System.out.println("Content ID : "+myList.getContentId());
System.out.println("User Blob Data : "+myList.getData());
Blob responseBody =myList.getData();
ObjectMapper objectMapper = new ObjectMapper();
List<ModelData> myDat = objectMapper.readValue((DataInput)
responseBody,objectMapper.getTypeFactory().constructCollectionType
(List.class,ModelData.class));
for (ModelData dt : myDat) {
System.out.println("User Name : "+dt.Name);
System.out.println("Users Email : "+dt.Email);
}
}
Please note, I have defined my ModelData elements as all String.
Any suggestion? What am I missing?
Thanks in advance!
The toString() representation hints at the object's type com.mysql.cj.jdbc.Blob. If you look up its javadoc (or the interface it implements) you'll see the options that you have to decode the contents of the Blob, namely getting an InputStream or a byte[] representation, which you'd have to subject to the correct character set decoding to turn it into a String.
Make sure you nail the character set by testing it with all kinds of Unicode content, so that you don't have to fix badly encoded database content later when your table contains a lot of data in unknown encodings.
As you're using Liferay's Service Builder, you might want to share the relevant parts of your service.xml (optional model-hints.xml) to check for an easier implementation.
I finally got this working by changing the field in question to String and addining a max length to certain number of Char
Thanks!

discrepancy in CRX property data types in AEM

While configuring mail service com.day.cq.mailer.DefaultMailService, I came to know that SMTP port should be an integer (smtp.port=I"465").
But if I try configuring using sling:OsgiConfig node, as the CRX is not providing Integer for data type (only Decimal, Double and Long), I am not able to achieve this.
Is there any alternative?
Use String type in sling:OsgiConfig node to give the smtp:port in CRX/DE. This is internally processed by DefaultMailService.
If we see the DefaultMailService implementation smtp.port is String, is processed by annotations
#Property(intValue={25})
private static final String SMTP_PORT = "smtp.port";
Sandeep is wrong, the internal representation is not String. The SMTP_PORT variable is of type String, because it holds a label and not the field value.
The actual value is of type int.
But you can set the value to Long in crx.de, because the value will be internally cast to int then.
String might also work, but I did not test that.

Varchar or Blob object for very large string? in Mysql through Eclipselink

I have an application where I am going to store the JSON string in MySql database through Eclipselink JPA.
The JSON string can be of any length. Most of the time a String from a JSON file of length around 200 to 300 lines.
What is the best way to store the string? To use varchar or Blob?
Please provide an example if any.
You should not save it as a BLOB, as it is primarily used for image data or other binary data... Use Varchar() or use TEXT which has a size of 65535 characters if you are unsure about how many characters you might need to store..
There was a thread previously discussing WHEN to use varchar or text: Thread
To store text - use a TEXT column (or even a LONGTEXT), blobs are for binary.
Also if you're on Mysql 5.7+ - there's now a JSON data type, which is checked for being a correct json, stored more efficiently and have pretty manipulation methods

Sql Server Storing SHA256 String as Question Marks

I have followed this article on how to implement password hashing and salting
http://www.codeproject.com/Articles/608860/A-Beginners-Tutorial-for-Understanding-and-Impleme
I have implemented all the code mentioned in the article into my MVC 5 web application, however, whenever I store the PasswordHash and Salt, both of these strings save in my User table as question marks, e.g, ????????????????
The database I'm using is Sql Server 2008 R2. The two fields within my database User table have both got a datatype of Nvarchar(100)
I should also mention the data is being persisted to the database using Entity Framework 5.
Has anyone seen this before? I'm thinking it might be a datatype problem, i.e., shouldn't be Nvarchar, however, I don't really know.
Any help with this would be great.
Thanks.
There's a problem in Utility.cs:
public static string GetString(byte[] bytes)
{
char[] chars = new char[bytes.Length / sizeof(char)];
System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
return new string(chars);
}
The function is fed random bytes. This is not how you create a random string. Characters are not meant to store binary data. Such strings will be hard to swallow for many components.
Use Convert.ToBase64String and don't trust random articles on the web. Validate what you find with your own understanding before using it.
SHA256 are not string, are byte arrays. Use byte[] in your client code, use VARBINARY on the server code.

JSON string to byte[] JSONParseException

I've gotten a whole bunch of angularJS, rest and entity stuff working together to be able to save form data via REST in my POSTGRES DB.
However, I decided to try something different with one of the entity fields so that I can store longer bits of text in the DB. I wanted to use an Entity with a field as follows:
#Column
private int age;
#Lob
#Column(length = 2147483647)
private byte[] otherNeeds;
Now the entity was created just fine. I built my REST interface on top of that based from JBoss Forge scaffolding. Everything works fine with my saving of the form via REST as long as I keep the "otherNeeds" field empty.
Here's my form:
<input id="age" type="number" ng-model="primaryGuest.age"></input>
<input id="otherNeeds" type="text" ng-maxlength="2147483647" ng-model="primaryGuest.otherNeeds"></input>
All this data is passed through correctly into my JavaScript objects in AngularJS, and when I click the save() button, I can see the POST request go thru to my REST interface with the following payload:
{
otherNeeds: "jjjjjj"
age: "10"
}
However, the response back from the server is an exception:
Caused by: org.codehaus.jackson.JsonParseException: Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '"' (code 0x22) in base64 content
at [Source: org.apache.catalina.connector.CoyoteInputStream#1a37992c; line: 1, column: 67]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433) [jackson-core-asl-1.9.9-redhat-2.jar:1.9.9-redhat-2]
at org.codehaus.jackson.impl.Utf8StreamParser.getBinaryValue(Utf8StreamParser.java:402) [jackson-core-asl-1.9.9-redhat-2.jar:1.9.9-redhat-2]
at org.codehaus.jackson.map.deser.std.PrimitiveArrayDeserializers$ByteDeser.deserialize(PrimitiveArrayDeserializers.java:289)
at org.codehaus.jackson.map.deser.std.PrimitiveArrayDeserializers$ByteDeser.deserialize(PrimitiveArrayDeserializers.java:275)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:63) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]
at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]
at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:169) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]
... 33 more
So, I'm not sure how to handle this scenario to have my object be transformed into something that would be acceptable for the byte[] format. I have the option of going back to a standard "String" field but I want to be able to provide the user with an "unlimited" amount of text that they can provide.
Any suggestions would be much appreciated.
I'm not exactly sure what the issue was with the #Lob type column and why it didn't want to push the data into the DB; however, eventually, I changed from
#Lob
to
#Type(type="org.hibernate.type.StringClobType")
private String otherNeeds;
And then I was able to manage this more straightforwardly and push content into the DB via the REST calls.
When the property type is byte[] and the response is in String jackson thinks the data is base64 encoded and tries to decode it and convert it to byte[]. But when you changed the type to String no such conversion is taking place and the string is directly saved in database.