PGP Encryption - Compile time issue - java

I am trying to PGP Encrypt a file using Java code. I have generated pgp keys (.asc file) for the same. Below is my Java code:
package extract;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class PGPEncryption {
public static void main(String[] args) throws Exception {
String publicKeyFileName="abc-pub-sub.asc";
String keyUserid="abc";
String input_file_path="test.csv";
String output_file_path="/tmp/output";
camelContext.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(input_file_path).marshal()
.pgp(publicKeyFileName, keyUserid).to(output_file_path);
}
});
camelContext.start();
Thread.sleep(5000);
camelContext.stop();
}
}
Below are the Jars I added in my build Path :
bcpg-jdk15on-1.56.jar
bcprov-jdk15on-1.56.jar
camel-core-2.6.0.jar
camel-crypto-2.9.5.jar
commons-logging-1.2.jar
slf4j-api-1.7.25.jar
slf4j-nop-1.7.25.jar
But above code is giving me compile time error as below :
"The method pgp(String, String) is undefined for the type DataFormatClause<ProcessorDefinition<RouteDefinition>>"
Could someone please help me in fixing this ?
Also I tried to export my code as Runnable Jar with compile time errors. But after I execute my Jar file I am facing below error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/fusesource/commons/management/ManagementStrategy
I am not sure if I am missing any basic thing here. Could someone please help here? Thanks in Advance.
Referred Link : PGP Encryption with Apache Camel

Related

Cannot decrypt encrypted text through BasicTextEncryptor?

I am using BasicTextEncryptor Class to text encryption and decryption text.
While executing the class file I am getting an exception
Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.handleInvalidKeyException(StandardPBEByteEncryptor.java:1073)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.encrypt(StandardPBEByteEncryptor.java:924)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.encrypt(StandardPBEStringEncryptor.java:642)
at org.jasypt.util.text.StrongTextEncryptor.encrypt(StrongTextEncryptor.java:107)
at com.newposition.util.TestJascrypt.main(TestJascrypt.java:45)
I have refer some of the solution blog but still not able to sorted out the issue.
I have copied the policy jar file in the /jre/lib/security/.
Nut still I am getting the exception.
Can any one please help me.
Below is my encryptor class.
package com.myproject.util;
import java.io.IOException;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.util.binary.BasicBinaryEncryptor;
import org.jasypt.util.password.StrongPasswordEncryptor;
import org.jasypt.util.text.StrongTextEncryptor;
public class TestJascrypt {
public static StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
public static BasicBinaryEncryptor binaryEncryptor = new BasicBinaryEncryptor();
public static void main(String []sene) throws IOException{
StrongTextEncryptor textEncryptor = new StrongTextEncryptor();
textEncryptor.setPassword("abcd");
String myEncryptedText = textEncryptor.encrypt("abcd");
String plainText = textEncryptor.decrypt(myEncryptedText);
System.out.println(plainText +" ##############");
}
}
Thanks in advance.

Crawljax - Require jars file for dynamic webpage crawling

I am trying to crawl the javascript webpages(content present within IFrame html tag) using Crawljax. I have added slf4j, crawljax 2.1 and Guava 18.0 jar to the application.
Error Message displayed in popup:
cannot find symbol
import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuild‌​er;
symbol: class CrawljaxConfigurationBuilder
location: class CrawljaxConfiguration.
Code:
import com.crawljax.core.CrawlerContext;
import com.crawljax.core.CrawljaxRunner;
import com.crawljax.core.configuration.CrawljaxConfiguration;
import com.crawljax.core.configuration.CrawljaxConfiguration.CrawljaxConfigurationBuilder;
import com.crawljax.core.plugin.OnNewStatePlugin;
import com.crawljax.core.state.StateVertex;
public class CrawljaxExamples {
public static void main(String[] args) {
CrawljaxConfigurationBuilder builder
= CrawljaxConfiguration.builderFor("http://help.syncfusion.com/ug/wpf/default.htm#!documents/overview.htm");
builder.addPlugin(new OnNewStatePlugin() {
#Override
public void onNewState(CrawlerContext context, StateVertex newState) {
}
#Override
public String toString() {
return "Our example plugin";
}
});
CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
crawljax.call();
}
}
Error Message:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class CrawljaxConfigurationBuilder
location: class com.crawljax.core.configuration.CrawljaxConfiguration
at crawljaxexamples.CrawljaxExamples.<clinit>(CrawljaxExamples.java:12)
Exception in thread "main" Java Result: 1
Same code could be found in below Link,
https://github.com/crawljax/crawljax/blob/master/examples/src/main/java/com/crawljax/examples/PluginExample.java
Can someone please tell what are jars files required to run this program? Or is there any settings to be changed in IDE?
Thanks
It seems you are using old version of crawljax.
Download latest version crawljax-cli-3.5.1.zip
Add all jars from lib folder and crawljax-cli-3.5.1.jar from the main folder as lib path.
Tested and now it works well.

Not able to connect to ARServer

Here is my code:
import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.ARServerUser;
public class ARServer {
public static void main(String[] args) {
ARServerUser ar = new ARServerUser();
ar.setServer("ServerName");
ar.setUser("Username");
ar.setPassword("Password");
ar.connect();
ar.login();
try {
ar.verifyUser();
} catch (ARException e) {
System.out.println(e.getMessage());
}
}
}
I have created build path for this jar file "ardoc7604_build002.jar" but still i am getting errors like:
import com.bmc.arsys.api.ARException can not be resolved
import com.bmc.arsys.api.ARServerUser; can not be resolved
ARserver can not be resolved
ARException can not be resolved to a type.
Thanks in advance for help.
you have put the javadoc jar in your path - you need to use the java api jar instead.
arapi7604_build002.jar
are you Only Java person or do you understand C# aswell if so I can give you some examples

Java-Sandbox example throwing java.lang.NoClassDefFoundError

Anyone with experience using Java-Sandbox, I have implemented one of the basic examples found in the documentation but i cant get it working.
Code:
SandPlayground.java
import java.util.concurrent.TimeUnit;
import net.datenwerke.sandbox.*;
import net.datenwerke.sandbox.SandboxContext.AccessType;
import net.datenwerke.sandbox.SandboxContext.RuntimeMode;
import net.datenwerke.sandbox.SandboxedEnvironment;
public class SandPlayground {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("Running...");
SandboxService sandboxService = SandboxServiceImpl.initLocalSandboxService();
// configure context
SandboxContext context = new SandboxContext();
//context.setRunRemote(true);
context.setRunInThread(true);
context.setMaximumRunTime(2, TimeUnit.SECONDS, RuntimeMode.ABSOLUTE_TIME);
context.addClassPermission(AccessType.PERMIT, "java.lang.System");
context.addClassPermission(AccessType.PERMIT, "java.io.PrintStream");
//run code in sandbox
SandboxedCallResult<String> result = sandboxService.runSandboxed(MyEnvironment.class, context, "This is some value");
// output result
System.out.println(result.get());
}
}
MyEnvironment.java
import net.datenwerke.sandbox.SandboxedEnvironment;
public class MyEnvironment implements SandboxedEnvironment<String> {
private final String myValue;
public MyEnvironment(String myValue){
this.myValue = myValue;
}
#Override
public String execute() throws Exception {
/* run untrusted code */
System.out.println(myValue);
/* return some value */
return "This is a different value";
}
}
And I'm getting the error:
EDIT: I've included the dependencies, but I'm still getting some errors:
With the code above I get:
Exception in thread "main" net.datenwerke.sandbox.exception.SandboxedTaskKilledException: killed task as maxmimum runtime was exceeded
at net.datenwerke.sandbox.SandboxMonitorDaemon.testRuntime(SandboxMonitorDaemon.java:82)
at net.datenwerke.sandbox.SandboxMonitorDaemon.run(SandboxMonitorDaemon.java:57)
at java.lang.Thread.run(Thread.java:724)
and when i remove the context.setMaximumRunTime() call, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/IdentityMap ...
Any help is much appreciated.
most likely you are missing the javassist library (see the documentatio of the sandbox for dependencies: http://blog.datenwerke.net/p/the-java-sandbox.html). You'll find the javassist library on sourceforge at: https://sourceforge.net/projects/jboss/files/Javassist/
The javaassist library is used to remove finalizers in loaded code. This can be turned off in the sandbox context:
contex.setRemoveFinalizers(false)
Hope this helps.

error while trying to generate stub file

When i try to generate a stub file using :rmic RemoteMethodImpl
I get the following error :
error: File .\RemoteMethodImpl.class does not contain type RemoteMethodImpl as expected, but type InterfaceImplementation.RemoteMethodImpl. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
error: Class RemoteMethodImpl not found.
2 errors
What error is this ? Why do i get this ?
Upon the request of # Shashank Kadne
package InterfaceImplementation;
import Interfaces.RemoteMethodIntf;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import Design.Main_Design_Client;
/**
*
* #author program-o-steve
*/
public class RemoteMethodImpl extends UnicastRemoteObject implements RemoteMethodIntf{
public RemoteMethodImpl() throws Exception{}
#Override
public void send(String IP,String Message) throws RemoteException {
Main_Design_Client mdc = new Main_Design_Client();
mdc.jTextArea1.setText("<html><b>Message from :</b></html>" + IP);
mdc.jTextArea1.setText("<html><b>Message :</b></html>" + Message);
}
}
I am assuming you are in a directory just outside "InterfaceImplementation" folder.
Execute : rmic InterfaceImplementation.RemoteMethodImpl
Yes, I was trying
% rmic GumballMachine
but changed after reading it from
% rmic gumball\GumballMachine
to
%rmic gumball.GumballMachine
which works fine. Sometimes, I wonder what a blockhead I am!!
When i try to generate a stub file
Stop right there. You haven't needed to do that for about eight years.
public RemoteMethodImpl() throws Exception{}
Just change that to call super() and you won't need a stub at all. See the preamble to the Javadoc for java.rmi.server.UnicastRemoteObject.

Categories

Resources