Mr. St33l
Mr. St33l

Reputation: 11

The method decodeBase64(byte[]) in the type Base64 is not applicable for the arguments (String)

Upgraded from Java 1.6.2 to Java 1.7.25 and now on my JSP upon compiling I am getting the following:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/dswsbobje] threw exception [Unable to compile class for JSP:

An error occurred at line: 40 in the jsp file: encrypt.jsp The method decodeBase64(byte[]) in the type Base64 is not applicable for the arguments (String)

40:byte[] raw = Base64.decodeBase64(secret64);

An error occurred at line: 47 in the jsp file: encrypt.jsp The method encodeBase64URLSafeString(byte[]) is undefined for the type Base64

47:out.write ("User Name " + userid + ": " + Base64.encodeBase64URLSafeString(cipher.doFinal(userid.getBytes())));

What is causing these errors and how do I resolve them?

Upvotes: 1

Views: 6888

Answers (1)

Lothar
Lothar

Reputation: 5449

It seems that the class Base64 you're using was changed from one version to the other. You haven't provided the complete classname of this class but Google tells me that it should be Apache Commons Codec with version >= 1.4.

It seems that you somehow are now using an older version of this library, because the methods the compiler complains about are added with version 1.4, so if you now use an older one, the methods can't be found.

Replace the older library by a more recent one should fix your problem. Alternatively you can change the calls of the methods to ones that already existed in older versions, e.g.

byte[] raw = Base64.decodeBase64(secret64);

to

byte[] raw = Base64.decodeBase64(secret64.getBytes(charset));

and

Base64.encodeBase64URLSafeString(cipher.doFinal(userid.getBytes())));

to

new String(Base64.encodeBase64URLSafeString(cipher.doFinal(userid.getBytes(charset)))), "UTF-8");

Upvotes: 1

Related Questions