Unable to decrypt Java's cypher encryption stored in mysql 8 - java

I have mysql 8.0 database (collation utf-08).
Having Table tbl_test (collation utf-08.) with following field.
id int auto_increament
text varbarinary(100)
I have following values stored using Java's encrytion library
93e4431a51f1cdfd31e970e3e035b3d6
I am trying to decrypt using mysql 8.0. Here is my query
set #k = 'bisp123456pitbas';
set #iv = '7654gabasyd854f1';
SELECT id, CAST(AES_DECRYPT(text, #k, #iv) AS CHAR (150)) FROM tbl_test;
But always get empty result. It works in mysql 5.7.
Is there anyone can help me on this?
Looking forward.

Related

Fetch result set from a postgres Stored procedure in java

I created a postgres function which returns a set of ref cursors. When I call the stored procedure from java the JDBC statement build is
select * from ga_rpt_movement('CODE','2018-5-10','2018-5-10','2018-5-10','C','STAT1','2018-5-10','2018-5-10','12344','A','T','34',25,50,'M','1','firstname',0,10) as result
When I run the same query on postgres terminal it gives me the four coursors.
Now I am not able to understand how do I fetch this cursor data in java.
Any suggestions, ideas are welcome and appreciated.
Result set when I run this query on postgres terminal look like this :
p_cr_personstatus
p_cr_identification
p_cr_phone
p_cr_count
(4 rows)
I am trying to implement this using spring JPA only.

how to transform byte[] value of blob field in mysql to insert into statement

I want to select data from a mysql table, and then generate a sql script file for importing to another db.
The value type of blob in mysql is byte array in java. I have try to use new String(byte[], Charset) to transform it to String, using all charsets that java support. It can import successfully, but the imported value is incorrect. All the generated strings are not equal to what SQLyog generates.
how can i do?

Setting DB2SECURITYLABEL upon insert using Hibernate

I have a requirement to set the DB2SECURITYLABEL of a row upon inserting that row into the database via Hibernate. I've been unsuccessful thus far and I'm seeking advice on how to set the DB2SECURITYLABEL in Java and have Hibernate do the insert for me.
Inside of my entity, I have defined the following:
#Column(name="slabel") //this matches the name of the DB2SECURITYLABEL column
private byte[] slabel;
public void setSlabel(byte[] slabel){
this.slabel = slabel;
}
public byte[] getSlabel(){
return this.slabel;
}
In my controller I convert the hex string that represents my security label into a byte[], setSlabel with that byte[], and save the record through a Spring Data Repository .save(entity). Upon saving that record, the db2 driver throws an error:
SQLCODE=-20402 SQLSTATE=42519 .
This error code is indicative of a record being saved without a required DB2SECURITYLABEL.
Assumptions:
I am able to insert/select into/from this table via commandline using the same
security label. insert into schema.table (field1, slabel) values
(123,x'FFF01010101000CABBBBFFF') <-not my real label. I can select the records that I insert via commandline and in my application.
I am able to retrieve existing records with DB2SECURITYLABELS
and read the label as a byte[] and as hex string using my application.
I believe I am inserting a correct label. I have verified the byte[]
that I am applying to the object is correct. I was able to insert a
record with a valid DB2SECURITYLABEL via the commandline, and
retrieved it in my application; the two byte[] for the
DB2SECURITYLABELs are identical and convert back to the same hex
string.
Has anyone set a DB2SECURITYLABEL in a Java object as a byte[] and used Hibernate to save the data to a db2 database?
I appreciate any assistance.

Unicode messages in oracle raise_application_error

I am working on enabling globalization support in my DB.
I have done migrating character set to UTF (AL16UTF16).
After migration, I can pass Unicode characters from Java to Oracle and store in table's NVARCHAR2 column. Also I can retrieve from DB and pass to Java.
But, If I do a raise_application_error with the Unicode data. It sends the error message to java like below
; nested exception is java.sql.SQLException: ORA-20001: ¿¿¿ ¿¿¿¿¿¿¿¿¿
Can anyone tell me what's wrong? and how can I get the Unicode error messages in java?
Thanks in advance.
The problem is I have done character set migration using the below steps, but it doesn't work for me.
1.Backup the database.
2.Run CSSCAN command.
3.Restart the DB with RESTRICT mode.
4.Run CSALTER script.
5.Restart the DB.
After that I have tried using the below steps.
1.Take backup of the DB using expdp command.
2.Create a new database with required character set (Unicode AL32UTF8).
3.Import the backup dump file into the newly created DB.
That's all. It works!
Now I don't need to use NVARCHAR2 data type to store unicode data (VARCHAR2 itself stores Unicode). raise_application_error also works fine (sends error messages with Unicode data to Java).
Thanks.

Insert query with latin1_swedish_ci charset

I made a program that is generating me a INSERT queries for a MySql database. The database has 2 fields that are encoded with latin1_swedish_ci charset. If I run the query from PhpMyAdmin when I preview the content with my php script some special char (like "ó", "é"...) is not showed correctly.
I think the problem is that Java is encoding String as utf8 charset so when i copy paste the query in the phpmyadmin and i run it, the inserted record is generated with the wrong charset. How can I generate the correct query (with the correct charset) in Java?
Thanks In advance for your help

Categories