@@ -0,0 +1,2753 @@
+/*%0A * Copyright 2016    https://github.com/sdcuike Inc. %0A * All rights reserved.%0A *%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.doctor.commons.core.crypter;%0A%0Aimport java.security.KeyPair;%0Aimport java.security.KeyPairGenerator;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.PrivateKey;%0Aimport java.security.PublicKey;%0A%0Aimport com.doctor.beaver.annotation.Immutable;%0A%0A/**%0A * @author sdcuike%0A *%0A *         Created At 2017%E5%B9%B41%E6%9C%8817%E6%97%A5 %E4%B8%8B%E5%8D%8811:48:29%0A */%0A@Immutable%0Apublic final class RSAUtils %7B%0A    private static final String Key_Algorithm = %22RSA%22;%0A    private static final int    KEY_SIZE      = 2048;%0A%0A    public static RsaKeyPair generateKeyPair() throws NoSuchAlgorithmException %7B%0A        return generateKeyPair(KEY_SIZE);%0A    %7D%0A%0A    public static RsaKeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException %7B%0A        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(Key_Algorithm);%0A        keyPairGenerator.initialize(keySize);%0A        KeyPair keyPair = keyPairGenerator.genKeyPair();%0A        PublicKey publicKey = keyPair.getPublic();%0A        PrivateKey privateKey = keyPair.getPrivate();%0A%0A        return new RsaKeyPair(Base64Utils.encodeToString(publicKey.getEncoded()),%0A                Base64Utils.encodeToString(privateKey.getEncoded()));%0A    %7D%0A%0A    public static final class RsaKeyPair %7B%0A        private String base64PublicKey;%0A        private String base64PrivateKey;%0A%0A        public RsaKeyPair(String base64PublicKey, String base64PrivateKey) %7B%0A            this.base64PublicKey = base64PublicKey;%0A            this.base64PrivateKey = base64PrivateKey;%0A        %7D%0A%0A        public String getBase64PublicKey() %7B%0A            return base64PublicKey;%0A        %7D%0A%0A        public String getBase64PrivateKey() %7B%0A            return base64PrivateKey;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return %22RsaKeyPair %5Bbase64PublicKey=%22 + base64PublicKey + %22, base64PrivateKey=%22 + base64PrivateKey + %22%5D%22;%0A        %7D%0A    %7D%0A%7D%0A

add rsa