Here you can find the source of generateRSASHA1Signature(PrivateKey privateKey, String data)
Parameter | Description |
---|---|
data | - the data to be signed. |
key | - the signing key. |
Parameter | Description |
---|
public static String generateRSASHA1Signature(PrivateKey privateKey, String data) throws GeneralSecurityException
//package com.java2s; /**//from www . ja v a 2 s . c om * Copyright 2010-2011 Buhake Sindi Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.security.PrivateKey; import java.security.Signature; import sun.misc.BASE64Encoder; public class Main { /** * Computes RSA-SHA1 signature. * * @param data * - the data to be signed. * @param key * - the signing key. * @return The Base64-encoded RFC 2104-compliant HMAC signature. * @throws java.security.SignatureException * when signature generation fails */ public static String generateRSASHA1Signature(PrivateKey privateKey, String data) throws GeneralSecurityException { byte[] rsaSha1Data = null; try { Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(privateKey); signature.update(data.getBytes("UTF-8")); rsaSha1Data = signature.sign(); return new BASE64Encoder().encode(rsaSha1Data); } catch (UnsupportedEncodingException e) { // TODO: handle exception throw new GeneralSecurityException(e); } } }