How to convert string to key to be used in encryption? - java-me

Hi All
I want to convert the string (taken as input from user) into a secretkey.I am coding in J2ME.The algorithm used is blowfish.

The Java cryptography APIs are not available in Java ME.
You'll need to download the Bouncy Castle lightweight cryptography API, which supports Java ME. You can then extract the classes you need from there. I found a code example here that should help you get started.
About charsets: Java ME does indeed support UTF-8, so that's always a safe bet. And a good idea, yes, although you'll see a lot of code that doesn't specify a charset.

Edit: Please see Eric's answer. This is not available in J2ME.
To convert a string to a key, you can do:
String strkey = "My key goes here";
SecretKeySpec key = new SecretKeySpec(strkey.getBytes("UTF-8"), "Blowfish");

Related

encodeURIComponent Not working properly NodeJS

I'm trying to encode text of biography for Instagram change biography on profile and it doesnt accept my biography.
I used:
let bio = "111X#%(!#)!$(*!Gram)"
let biography = encodeURIComponent(bio)
and it failing. Need help please
Java equivalent to JavaScript's encodeURIComponent that produces identical output?
I need this but for NodeJS, so it generate same encoding as Java one.
There are some distinctions between Java's URI encoding and the JS encodeURIComponent functions. Spaces will translate to + in Java but they will translate to %20 in Javascript. The JS function uses UTF-8 by default, but Java could be using a different format for encoding (depending on your code editor). Take a look at this stack overflow post for more information: https://stackoverflow.com/a/25298843/9571755
Hope that helps and happy coding :)

What kind of LUA encoding is that?

everyone,
I am not so familiar with coding but I have been looking for hours now without answer. Maybe because I do not know what am I looking for.
I have found an LUA code with the below encoded code,
I was wondering which kind of encoding it is? Is there a specific name for it, is there a way to decrypt it? for the curious one, it looks like :
return(function(aaEE_IIlIllIlII,aaEE_lIlIIIIIlI,aaEE_llIIlIIllllIl)local aaEE_IIllllIIlIIllIlIIII=string.char;local aaEE_lIlllIlIllIIIlIlIl=string.sub;local aaEE_IlIlIIIllIlIIIllllIIIIIIl=table.concat;local aaEE_IIIIIIlllIIIIllllIlIII=math.ldexp;local aaEE_IIIlIIllIIllIIlIIllIllII=getfenv or function()return _ENV end;local aaEE_lIllIIIIIllllIlIlIl=select;local aaEE_lIlIlllIllIIII=unpack or table.unpack;local aaEE_llllIlllllIlIlIl=tonumber;local function aaEE_lllIllIIIlIIlllIIll(aaEE_IIlIllIlII)local aaEE_llllIIllllIll,aaEE_lIIlIlllIlllIIIllIIlIllI,aaEE_lIlIlllIllIIII="","",{}local aaEE_IlIllIlllIIlIllllIll=256;local aaEE_IIllIllIIIlIIlllIIlIII={}for aaEE_lIlIIIIIlI=0,aaEE_IlIllIlllIIlIllllIll-1 do aaEE_IIllIllIIIlIIlllIIlIII[aaEE_lIlIIIIIlI]=aaEE_IIllllIIlIIllIlIIII(aaEE_lIlIIIIIlI)end;local aaEE_lIlIIIIIlI=1;local function aaEE_IlIlllllllIIlI()local aaEE_llllIIllllIll=aaEE_llllIlllllIlIlIl(aaEE_lIlllIlIllIIIlIlIl(aaEE_IIlIllIlII,aaEE_lIlIIIIIlI,aaEE_lIlIIIIIlI),36)aaEE_lIlIIIIIlI=aaEE_lIlIIIIIlI+1;local aaEE_lIIlIlllIlllIIIllIIlIllI=aaEE_llllIlllllIlIlIl(aaEE_lIlllIlIllIIIlIlIl(aaEE_IIlIllIlII,aaEE_lIlIIIIIlI,aaEE_lIlIIIIIlI+aaEE_llllIIllllIll-1),36)aaEE_lIlIIIIIlI=aaEE_lIlIIIIIlI+aaEE_llllIIllllIll;return aaEE_lIIlIlllIlllIIIllIIlIllI end;aaEE_llllIIllllIll=aaEE_IIllllIIlIIllIlIIII(aaEE_IlIlllllllIIlI())aaEE_lIlIlllIllIIII[1]=aaEE_llllIIllllIll;while aaEE_lIlIIIIIlI<#aaEE_IIlIllIlII do local aaEE_lIlIIIIIlI=aaEE_IlIlllllllIIlI()if aaEE_IIllIllIIIlIIlllIIlIII[aaEE_lIlIIIIIlI]then aaEE_lIIlIlllIlllIIIllIIlIllI=aaEE_IIllIllIIIlIIlllIIlIII[aaEE_lIlIIIIIlI]else aaEE_lIIlIlllIlllIIIllIIlIllI=aaEE_llllIIllllIll..aaEE_lIlllIlIllIIIlIlIl(aaEE_llllIIllllIll,1,1)end;aaEE_IIllIllIIIlIIlllIIlIII[aaEE_IlIllIlllIIlIllllIll]=aaEE_llllIIllllIll..aaEE_lIlllIlIllIIIlIlIl(aaEE_lIIlIlllIlllIIIllIIlIllI,1,1)aaEE_lIlIlllIllIIII[#aaEE_lIlIlllIllIIII+1],aaEE_llllIIllllIll,aaEE_IlIllIlllIIlIllllIll=aaEE_lIIlIlllIlllIIIllIIlIllI,aaEE_lIIlIlllIlllIIIllIIlIllI,aaEE_IlIllIlllIIlIllllIll+1 end;return table.concat(aaEE_lIlIlllIllIIII)end;
https://pastebin.com/4HU5pFHZ
Thank you for your answers and explanation
Its called obfuscation (you can look up "lua obfuscator" or "script obfuscator" for more information) and just makes the code unreadable. I've already seen this obfuscation but i can't recall the name of it, its a paid one tho.
This is the best encryption see here.
1 = Let's encrypt lua code com or: LuaEncrypt.exe.
2 = Let's chamar or encrypted lua code.
3 = To call this encrypted code, we will use AmsLuac.dll created in C++
https://github.com/AmsPluginsBox/Encrypt-Lua-Code

Decode base64 to string and Encode string to base64 in XQuery

I needed to work with base64 in Xquery on a project and found almost nothing on Internet, thankfully there was one GitHub repository that had what I need to complete the encode-decode.
So, if you have a xs:string and you need to encode as base64 or you have a base64 string and need to decode as xs:string* you can use the XQuery on the repository that is highlighted as answer.
Obs: Comments are PT-BR, maybe you need to translate to understand what each function is used for
If your system supports it, use the EXPath binary library. Specification is at https://www.w3.org/2013/12/expath-binary-20131203/
See in particular the functions bin:encode-string($string, $encoding) which converts xs:string to xs:base64Binary, and bin:decode-string($in, $encoding) which converts xs:base64Binary to xs:string.
Your XQuery context also might come with a utility function that does the conversion.
eXist-db offers util:base64-encode and util:base64-decode.

string encoding error from delphi 7 to xe

i found on internet some source for crypt string and i saw that on delphi 7 the string is crypted and decrypted well, and when i try to do the same things with delphi xe2,xe3,xe4,xe5 the encryption end decryption fail with this error "invalid buffer size for decryption"
i'm using aes.pas and eiaes.pas from here: http://code.google.com/p/jalphi-lib/source/browse/trunk/codemyth/delphi/dontuseit/?r=7
i think that the problem is the enconding of string.
Is it possible to solve this problem?
The AES library you provided the link to has not been updated to support the fact that "String" in later versions of Delphi (Delphi 2009 onward) is now a UnicodeString where each character is a WideChar.
You have 4 options:
Contact the library author and ask if a Unicode version is
planned/available
Attempt to modify the library to support Unicode yourself (or find
someone who can/will help do this)
Find an alternative encryption library that already supports Unicode
Ensure that you only use ANSI Strings with the library.
This last option may not be viable for you but if it is then you will still need to modify the AES library, but you will not need to do any code changes.
The problem is that "String" and "Char" in the later versions of Delphi are "Wide" types (2 bytes per 'character'). This difference is almost certainly causing problems with code in the AES library that assumes only ONE byte per character.
You can make these assumptions valid by making sure that the AES code is working with ANSI Strings.
If you choose to do this, then I would suggest that you introduce two new types:
type
AESString = ANSIString;
AESChar = ANSIChar;
PAESChar = ^AESChar;
You will then need to go through the AES library code replacing any reference to "String" with "AESString", "Char" with "AESChar" and "PChar" with "PAESChar".
This should then make AES an ANSI String library and it will still be usable in Delphi 7 (i.e. pre-Delphi 2009) if that's important for you.
If you then find in the future that you do need to fully support Unicode strings and then need to properly fix the AES library code itself, you can do this and then simply change the AESString and AESChar types to:
type
AESString = String;
AESChar = Char;
If this is then compiled with a non-Unicode version of Delphi, the library will automatically revert back to ANSI String ("String" == ANSIString pre-D2009), so your Unicode changes will need to take this into account if you need to support both Unicode and non-Unicode versions of Delphi. You do need to be careful, but this is not difficult.

CakePHP Security::cipher decrypt not working

I am trying to decrypt a hashed string using
Security::cipher($strHashedPassword, Configure::read('Security.salt'));
doesn't seem to be giving the desired result. Does anyone have any experience with this? From the docs it looks like this should work.
Please note that you cannot decrypt a hashed string. Hashes are irreversible by definition. They can't be decrypted because they're not encrypted to begin with, they're hashed. If you're really trying to decrypt a password hash (as produced by the AuthComponent?) you're out of luck.
Security::cipher can only decrypt strings that it encrypted as well, in which case you'd be talking about a cipher text, not a hash.
If you can demonstrate that this doesn't print "test":
$cipherText = Security::cipher('test', Configure::read('Security.salt'));
echo Security::cipher($cipherText, Configure::read('Security.salt'));
you have found a bug in Cake, most likely the one linked to by #infinity. Otherwise, you're trying something impossible.
Hi have a look at CakePHP forum:
http://cakephp.lighthouseapp.com/projects/42648/tickets/471-securitycipher-function-cannot-decrypt

Resources