Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Jasypt解密_Java_Encryption_Windows 8_Java 7_Jasypt - Fatal编程技术网

Java 使用Jasypt解密

Java 使用Jasypt解密,java,encryption,windows-8,java-7,jasypt,Java,Encryption,Windows 8,Java 7,Jasypt,如何使用库解密加密的密码 尝试解密密码时控制台中显示错误: Encrypted: JIOYXNa1+3+QefY2S7sas7LmhyOuDQcG8TTsQoTkqj0OtobCvwAFHXxoTr7z6HuP org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encrypti

如何使用库解密加密的密码

尝试解密密码时控制台中显示错误:

Encrypted: JIOYXNa1+3+QefY2S7sas7LmhyOuDQcG8TTsQoTkqj0OtobCvwAFHXxoTr7z6HuP
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:999)
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:976)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.util.text.StrongTextEncryptor.decrypt(StrongTextEncryptor.java:118)
    at com.uk.mysqlmaven.jsf.test.PasswordEncryptionDecryptionUsingJASYPT.main(PasswordEncryptionDecryptionUsingJASYPT.java:22)

你可以试试下面的例子。这将为您工作:请始终保持mpCryptoPassword值非常机密的位置,只有应用程序才能读取该值

public class EncryptionDecryptionUsingJASYPT {

    private static String mpCryptoPassword = "BornToFight";

    public static void main(String[] args) {
        String value = "Original Text: Eclipse";

        System.out.println("Original Value : "+value);
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(mpCryptoPassword);
        String encryptedPassword = encryptor.encrypt(value);
        System.out.println(encryptedPassword);

        StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor();
        decryptor.setPassword(mpCryptoPassword);
        System.out.println(decryptor.decrypt(encryptedPassword));
    }
}

从命令生成的加密字符串未给出所需的结果,因为它无法加密像“!”这样的特殊字符。并给出错误“未找到事件”

KAD@ashutoshMINGW64~/桌面

$java-cp ~/.m2/repository/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input=“Test!email30#password”password=“some_salt” 算法=PBEWithMD5和DES

巴什:!email30#密码:未找到事件

下面是一个使用
org.jasypt.util.text.AES256TextEncryptor
这是一个实用类,用于轻松执行
文本的高强度加密

该类内部包含一个
标准bStringEncryptor
,配置方式如下:

  • 算法:
    PBEWithHMACSHA512AndAES_256

  • 关键获取迭代:
    1000

使用它所需的步骤包括:

  • 创建一个实例(使用new)
  • 设置密码(使用setPassword(字符串)或setPasswordCharArray(char[])
  • 执行所需的加密(字符串)或解密(字符串)操作
  • pom.xml:

    <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
    
    import org.jasypt.util.text.AES256TextEncryptor;
    import java.security.NoSuchAlgorithmException;
    
    public class JasyptPasswordEcryptor {
     public static void main(String[] args) throws NoSuchAlgorithmException {
    
        String password = "Test!email30#password";
    
        AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword("some_salt");
        String myEncryptedText = encryptor.encrypt(password);
        System.out.println("Encrypted: "+myEncryptedText);
    
        String plainText = encryptor.decrypt(myEncryptedText);
        System.out.println("Decrypted: "+plainText);
     }
    }
    
    email:
        password:
            # DO-NOT-USE/REMOVE THIS
            plain: 'Test!email30#password'
            # use this encrypted one
            encrypted: ENC(fureWQHrflMinY+KBOcNeJyYmQv+7Ung/IclGz3iSBYKqTNdgslADg+TMcfFI/unaqZ/P3kDGPco2jZ4vIhrFw==)
    
    jasypt:
        encryptor:
            password: some_salt
    
    输出:

    <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
    
    import org.jasypt.util.text.AES256TextEncryptor;
    import java.security.NoSuchAlgorithmException;
    
    public class JasyptPasswordEcryptor {
     public static void main(String[] args) throws NoSuchAlgorithmException {
    
        String password = "Test!email30#password";
    
        AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword("some_salt");
        String myEncryptedText = encryptor.encrypt(password);
        System.out.println("Encrypted: "+myEncryptedText);
    
        String plainText = encryptor.decrypt(myEncryptedText);
        System.out.println("Decrypted: "+plainText);
     }
    }
    
    email:
        password:
            # DO-NOT-USE/REMOVE THIS
            plain: 'Test!email30#password'
            # use this encrypted one
            encrypted: ENC(fureWQHrflMinY+KBOcNeJyYmQv+7Ung/IclGz3iSBYKqTNdgslADg+TMcfFI/unaqZ/P3kDGPco2jZ4vIhrFw==)
    
    jasypt:
        encryptor:
            password: some_salt
    
    加密: fureWQHrflMinY+KBOcNeJyYmQv+7Ung/IclGz3iSBYKqTNdgslADg+TMcfFI/unaqZ/P3kDGPco2jZ4vIhrFw==

    解密:测试!email30#密码

    春季开机集成:

    <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
    
    import org.jasypt.util.text.AES256TextEncryptor;
    import java.security.NoSuchAlgorithmException;
    
    public class JasyptPasswordEcryptor {
     public static void main(String[] args) throws NoSuchAlgorithmException {
    
        String password = "Test!email30#password";
    
        AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword("some_salt");
        String myEncryptedText = encryptor.encrypt(password);
        System.out.println("Encrypted: "+myEncryptedText);
    
        String plainText = encryptor.decrypt(myEncryptedText);
        System.out.println("Decrypted: "+plainText);
     }
    }
    
    email:
        password:
            # DO-NOT-USE/REMOVE THIS
            plain: 'Test!email30#password'
            # use this encrypted one
            encrypted: ENC(fureWQHrflMinY+KBOcNeJyYmQv+7Ung/IclGz3iSBYKqTNdgslADg+TMcfFI/unaqZ/P3kDGPco2jZ4vIhrFw==)
    
    jasypt:
        encryptor:
            password: some_salt
    
    您可以在任何配置类或SpringBootApplication中使用
    @EnableEncryptableProperties
    。见示例:

    import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.domain.EntityScan;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    @EnableEncryptableProperties
    @SpringBootApplication
    @ComponentScan(basePackages = {"com.company"})
    @EntityScan(basePackages = {"com.company.persistence.entities"})
    @EnableJpaRepositories(value = {"com.company.persistence.repository"})
    @EnableTransactionManagement
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }
    
    并且在任何属性/yml文件中:

    <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
    
    import org.jasypt.util.text.AES256TextEncryptor;
    import java.security.NoSuchAlgorithmException;
    
    public class JasyptPasswordEcryptor {
     public static void main(String[] args) throws NoSuchAlgorithmException {
    
        String password = "Test!email30#password";
    
        AES256TextEncryptor encryptor = new AES256TextEncryptor();
        encryptor.setPassword("some_salt");
        String myEncryptedText = encryptor.encrypt(password);
        System.out.println("Encrypted: "+myEncryptedText);
    
        String plainText = encryptor.decrypt(myEncryptedText);
        System.out.println("Decrypted: "+plainText);
     }
    }
    
    email:
        password:
            # DO-NOT-USE/REMOVE THIS
            plain: 'Test!email30#password'
            # use this encrypted one
            encrypted: ENC(fureWQHrflMinY+KBOcNeJyYmQv+7Ung/IclGz3iSBYKqTNdgslADg+TMcfFI/unaqZ/P3kDGPco2jZ4vIhrFw==)
    
    jasypt:
        encryptor:
            password: some_salt
    

    @ᴜʀᴇsʜᴀᴛᴛᴀ 我们能解密加密的密码吗?是的,为什么不能。毕竟,它也是一个简单的字符串,就像任何其他字符串一样。如果它散列,则无法获取它。让我们看看CLI示例的问题是“!”是保留的shell字符。如果在该字符串周围使用单个QOUTE,则会阻止shell解释“!”并按预期工作。该错误消息来自您的shell,而不是Jasypt jar