How does Maven 3 password encryption work?

前端 未结 3 497
南方客
南方客 2021-02-03 23:38

I\'m trying to understand Maven 3\'s[password encryption feature. I have found that this feature is poorly documented and confusing. For example, the feature documentation and a

3条回答
  •  既然无缘
    2021-02-04 00:01

    Here is example code which shows how to decrypt the maven master password from

    ~/.m2/security-settings.xml

    and also the server passwords from

    ~/.m2/settings.xml

    Source of MavenPasswordDecryptor.java

    import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
    
    public class MavenPasswordDecryptor {
        public static void main(String[] args) throws Exception {
    
            if (args.length < 1 || args.length > 2 ) {
                System.out.println("Usage: java -jar maven-password-decryptor.jar ");
                System.out.println("Usage: java -jar maven-password-decryptor.jar  ");
                return;
            }
    
            DefaultPlexusCipher cipher = new DefaultPlexusCipher();
    
            String encryptedPassword = args[0];
            String passPhrase = (args.length == 2 && args[1] != null && !args[1].isEmpty()) ? args[1] : "settings.security";
    
            String result = cipher.decryptDecorated(encryptedPassword, passPhrase);
    
            System.out.println(result);
        }
    }
    

    There is also an example project on GitHub:

    https://github.com/uweguenther/maven-password-decryptor

提交回复
热议问题