Code example for RSAPublicKey

Methods: getModulus, getPublicExponent

0
 
            Digest digest = new SHA512Digest();
            Digest mgf1digest = new SHA512Digest();
            PSSSigner signer = new PSSSigner(rsa, digest, mgf1digest, 512 / 8);
            RSAKeyParameters params = new RSAKeyParameters(false,
                    pubKey.getModulus(), pubKey.getPublicExponent());
            signer.init(true, params);
 
            byte[] signedData = toSign.getBytes("UTF-8");
            signer.update(signedData, 0, signedData.length);
            byte[] signature = signer.generateSignature();
 
            return toBase64(signature);
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (DataLengthException e) {
            throw new RuntimeException(e);
        } catch (CryptoException e) {
            throw new RuntimeException(e);