Example usage for java.security GeneralSecurityException GeneralSecurityException

List of usage examples for java.security GeneralSecurityException GeneralSecurityException

Introduction

In this page you can find the example usage for java.security GeneralSecurityException GeneralSecurityException.

Prototype

public GeneralSecurityException(Throwable cause) 

Source Link

Document

Creates a GeneralSecurityException with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.nebula.service.auth.AuthenticationHelper.java

private void createAuthorization() throws GeneralSecurityException {

    if (StringUtils.isBlank(signedSignature)) {
        throw new GeneralSecurityException("The header " + Request.AUTHORIZATION_HEADER + " is illegal");
    }//from  w ww  .  j  ava 2s . com

    authorization = Authorization.build(signedSignature);

}

From source file:net.bioclipse.opentox.api.Task.java

public static void delete(String task) throws IOException, GeneralSecurityException {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(task);
    method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
    client.executeMethod(method);/*  w ww  .  j  a v  a 2s.  c  o m*/
    int status = method.getStatusCode();
    switch (status) {
    case 200:
        // excellent, it worked
        break;
    case 401:
        throw new GeneralSecurityException("Not authorized");
    case 404:
        // not found, well, I guess equals 'deleted'
        break;
    case 503:
        throw new IOException("Service unavailable");
    default:
        throw new IOException("Unknown server state: " + status);
    }
}

From source file:de.openflorian.crypt.provider.XorCipher.java

@Override
public String encrypt(String plain) throws GeneralSecurityException {
    if (StringUtils.isEmpty(plain))
        throw new IllegalArgumentException("String AND Key may not be empty.");
    if (StringUtils.isEmpty(key))
        throw new IllegalStateException("Xor cipher key is not set.");

    char[] keychars = key.toCharArray();
    char[] targetchars = plain.toCharArray();

    int keycharsLength = keychars.length, targetcharsLength = targetchars.length;

    char[] newtarget = new char[targetcharsLength];

    for (int i = 0; i < targetcharsLength; i++)
        newtarget[i] = (char) (targetchars[i] ^ keychars[i % keycharsLength]);

    keychars = null;/*from  w  ww .  ja  v a2 s .  com*/
    targetchars = null;

    try {
        return new String(new Base64().encode(new String(newtarget).getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        throw new GeneralSecurityException(e);
    }
}

From source file:org.nebula.service.auth.AuthenticationInterceptor.java

private void checkIfAccessAdminUrls(AuthenticationHelper helper, HttpServletRequest request)
        throws GeneralSecurityException {

    if (!helper.isAdmin()) {

        String contextPath = request.getContextPath();
        String requestUri = request.getRequestURI();

        for (String url : adminUrls) {
            if (requestUri.startsWith(contextPath + url)) {
                throw new GeneralSecurityException(
                        "The user is not allowed to access the url " + (contextPath + url));
            }//from w  ww.j  av  a 2  s  . co  m
        }
    }
}

From source file:org.glite.slcs.pki.bouncycastle.CMCPKIResponse.java

/**
 * Constructor. Decode the CMS signed data in the BC CMSSignedData object.
 * /*  ww w  .ja  va2s. com*/
 * @param signedData
 *            The byte array of of the CMS Signed Data
 * @throws GeneralSecurityException
 *             If an error occurs.
 */
public CMCPKIResponse(byte[] signedData) throws GeneralSecurityException {
    try {
        LOG.debug("decode CMSSignedData...");
        CMSSignedData cmsSignedData = new CMSSignedData(signedData);
        certificatesStore_ = cmsSignedData.getCertificatesAndCRLs("Collection",
                BouncyCastleProvider.PROVIDER_NAME);
    } catch (CMSException e) {
        throw new GeneralSecurityException("CMSException: " + e);
    }
}

From source file:org.apache.shindig.common.crypto.Crypto.java

/**
 * HMAC sha1/* w  w  w.  ja  va 2 s.  c  om*/
 * 
 * @param key the key must be at least 8 bytes in length.
 * @param in byte array to HMAC.
 * @return the hash
 * 
 * @throws GeneralSecurityException
 */
public static byte[] hmacSha1(byte[] key, byte[] in) throws GeneralSecurityException {
    if (key.length < MIN_HMAC_KEY_LEN) {
        throw new GeneralSecurityException("HMAC key should be at least " + MIN_HMAC_KEY_LEN + " bytes.");
    }
    Mac hmac = Mac.getInstance(HMAC_TYPE);
    Key hmacKey = new SecretKeySpec(key, HMAC_TYPE);
    hmac.init(hmacKey);
    hmac.update(in);
    return hmac.doFinal();
}

From source file:com.oneops.cms.crypto.CmsCryptoDES.java

/**
 * Encrypt.//from   w  ww  . j  a va  2  s  .co m
 *
 * @param instr the instr
 * @return the string
 * @throws java.security.GeneralSecurityException the general security exception
 */
@Override
public String encrypt(String instr) throws GeneralSecurityException {
    long t1 = System.currentTimeMillis();
    byte[] in = instr.getBytes();
    PaddedBufferedBlockCipher encryptor = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESedeEngine()));
    encryptor.init(true, keyParameter);
    byte[] cipherText = new byte[encryptor.getOutputSize(in.length)];
    int outputLen = encryptor.processBytes(in, 0, in.length, cipherText, 0);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        encryptor.doFinal(cipherText, outputLen);
        Hex.encode(cipherText, os);
    } catch (Exception e) {
        e.printStackTrace();
        throw new GeneralSecurityException(e);
    }
    long t2 = System.currentTimeMillis();
    logger.debug("Time taken to encrypt(millis) :" + (t2 - t1));
    return ENC_PREFIX + os.toString();
}

From source file:org.sipfoundry.sipxconfig.cert.CertificateGenerator.java

@Override
public X509Certificate createCertificate() throws GeneralSecurityException {
    try {/*ww w.ja v  a2  s. c om*/
        KeyPair pair = getKeyPair();
        X509v3CertificateBuilder gen = createCertificateGenerator(m_issuer, pair.getPublic());
        gen.addExtension(X509Extension.subjectKeyIdentifier, false,
                new SubjectKeyIdentifierStructure(pair.getPublic()));
        gen.addExtension(X509Extension.basicConstraints, false, new BasicConstraints(false));

        List<GeneralName> names = new ArrayList<GeneralName>();
        if (StringUtils.isNotBlank(m_sipDomain)) {
            names.add(new GeneralName(GeneralName.uniformResourceIdentifier, format("sip:%s", m_sipDomain)));
        }
        names.add(new GeneralName(GeneralName.dNSName, getCommonName()));
        gen.addExtension(X509Extension.subjectAlternativeName, false,
                new GeneralNames((GeneralName[]) names.toArray(new GeneralName[names.size()])));

        return CertificateUtils.generateCert(gen, getAlgorithm(), getAuthorityPrivateKey());
    } catch (CertIOException e) {
        throw new GeneralSecurityException(e);
    }
}

From source file:org.glite.slcs.pki.Certificate.java

/**
 * Creates a certificate with its chain.
 * /*  w ww .ja v a  2 s  .  c  o  m*/
 * @param cert
 *            The X509Certificate
 * @param chain
 *            The chain as an array of X509Ceritificate.
 * @throws GeneralSecurityException
 *             If the certificate is null.
 */
public Certificate(X509Certificate cert, X509Certificate[] chain) throws GeneralSecurityException {
    if (cert == null) {
        throw new GeneralSecurityException("X509Certificate is null");
    }
    this.cert_ = cert;
    this.chain_ = chain;
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.ProxyTool.java

/**
 * Verify./*from   w  w w  . j a  va  2  s . c om*/
 * 
 * @throws GeneralSecurityException the general security exception
 */
private void verify() throws GeneralSecurityException {
    RSAPublicKey pkey = (RSAPublicKey) this.certificates[0].getPublicKey();
    RSAPrivateKey prkey = (RSAPrivateKey) userKey;

    if (!pkey.getModulus().equals(prkey.getModulus())) {
        throw new GeneralSecurityException("Certificate and private key specified do not match");
    }

}