MySQL column encryption with Hibernate in Spring MVC
I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.
I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.
Here's the code that has got me furthest
@Column(name="disability_description")
@Length(max=500)
@ColumnTransformer(
read = "AES_DECRYPT(disability_description, 'mykey')",
write = "AES_ENCRYPT(?, 'mykey')"
)
private String disabilityDescription;
This, however, doesn't work as I get the following errors
org.hibernate.exception.GenericJDBCException: could not execute statement
java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1
Please point in the right direction. I am lost. Also mykey
doesn't point to anything, I just entered a random word.
spring hibernate spring-mvc
add a comment |
I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.
I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.
Here's the code that has got me furthest
@Column(name="disability_description")
@Length(max=500)
@ColumnTransformer(
read = "AES_DECRYPT(disability_description, 'mykey')",
write = "AES_ENCRYPT(?, 'mykey')"
)
private String disabilityDescription;
This, however, doesn't work as I get the following errors
org.hibernate.exception.GenericJDBCException: could not execute statement
java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1
Please point in the right direction. I am lost. Also mykey
doesn't point to anything, I just entered a random word.
spring hibernate spring-mvc
add a comment |
I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.
I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.
Here's the code that has got me furthest
@Column(name="disability_description")
@Length(max=500)
@ColumnTransformer(
read = "AES_DECRYPT(disability_description, 'mykey')",
write = "AES_ENCRYPT(?, 'mykey')"
)
private String disabilityDescription;
This, however, doesn't work as I get the following errors
org.hibernate.exception.GenericJDBCException: could not execute statement
java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1
Please point in the right direction. I am lost. Also mykey
doesn't point to anything, I just entered a random word.
spring hibernate spring-mvc
I need to encrypt data saved onto my DB. I am currently using spring and hibernate to save data.
I have looked at some materials and tried to implement the code, however, it has resulted in various generic errors, some of the material was not targeted to MySQL etc.
Here's the code that has got me furthest
@Column(name="disability_description")
@Length(max=500)
@ColumnTransformer(
read = "AES_DECRYPT(disability_description, 'mykey')",
write = "AES_ENCRYPT(?, 'mykey')"
)
private String disabilityDescription;
This, however, doesn't work as I get the following errors
org.hibernate.exception.GenericJDBCException: could not execute statement
java.sql.SQLException: Incorrect string value: 'xF9x82ux01x99x1A...' for column 'disability_description' at row 1
Please point in the right direction. I am lost. Also mykey
doesn't point to anything, I just entered a random word.
spring hibernate spring-mvc
spring hibernate spring-mvc
asked Nov 22 '18 at 15:44
Yanis KYanis K
6810
6810
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I doubt that your column is not of type BINARY:
Mysql Doc:
AES_ENCRYPT() encrypts the string str using the key string key_str and
returns a binary string containing the encrypted output.
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434384%2fmysql-column-encryption-with-hibernate-in-spring-mvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I doubt that your column is not of type BINARY:
Mysql Doc:
AES_ENCRYPT() encrypts the string str using the key string key_str and
returns a binary string containing the encrypted output.
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
add a comment |
I doubt that your column is not of type BINARY:
Mysql Doc:
AES_ENCRYPT() encrypts the string str using the key string key_str and
returns a binary string containing the encrypted output.
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
add a comment |
I doubt that your column is not of type BINARY:
Mysql Doc:
AES_ENCRYPT() encrypts the string str using the key string key_str and
returns a binary string containing the encrypted output.
I doubt that your column is not of type BINARY:
Mysql Doc:
AES_ENCRYPT() encrypts the string str using the key string key_str and
returns a binary string containing the encrypted output.
answered Nov 22 '18 at 15:58
hasnaehasnae
1,2651016
1,2651016
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
add a comment |
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
Yes, you are absolutely correct. Thank you for your time you got this spot on, I changed it to VARBINARY and voila! Happens all the time, spend all this time doing something and then it is so simple and right in front of you. Thanks again
– Yanis K
Nov 22 '18 at 16:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434384%2fmysql-column-encryption-with-hibernate-in-spring-mvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown