本文整理汇总了Java中java.security.GeneralSecurityException类的典型用法代码示例。如果您正苦于以下问题:Java GeneralSecurityException类的具体用法?Java GeneralSecurityException怎么用?Java GeneralSecurityException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeneralSecurityException类属于java.security包,在下文中一共展示了GeneralSecurityException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.security.GeneralSecurityException; //导入依赖的package包/类
public static void main(final String[] argv) throws IOException, InvalidKeySpecException, NoSuchPaddingException,
InvalidKeyException, InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException,
InvalidAlgorithmParameterException, ClassNotFoundException, GeneralSecurityException {
if(argv.length >= 2) {
ip = argv[0];
port = Integer.parseInt(argv[1]);
} else {
Logger.getLogger(Main.class.getName()).log(Level.INFO, "Default ip and port were applied.");
ip = Parameters.RELAY_IP;
port = Parameters.RELAY_PORT_WALLET_LISTENER;
}
// Init connection with relay
try {
RelayConnection.getInstance();
} catch(IOException ex) {
Logger.getLogger(Main.class.getName()).severe(ex.getMessage());
return;
}
new ClientApplication();
}
示例2: sign
import java.security.GeneralSecurityException; //导入依赖的package包/类
private byte[] sign(byte[] message) throws GeneralSecurityException {
if (privateKey == null) {
throw new IllegalStateException("need to set private key with " +
"OAuthConsumer.setProperty when " +
"generating RSA-SHA1 signatures.");
}
Signature signer = Signature.getInstance("SHA1withRSA");
signer.initSign(privateKey);
signer.update(message);
return signer.sign();
}
示例3: createJWT
import java.security.GeneralSecurityException; //导入依赖的package包/类
public String createJWT(String username, Set<String> groups)
throws GeneralSecurityException, IOException {
// Create and Base64 encode the header portion of the JWT
JsonObject headerObj =
Json.createObjectBuilder()
.add("alg", "RS256") /* Algorithm used */
.add("typ", "JWT") /* Type of token */
// .add("kid", "default") /* Hint about which key to use to sign, but the signature is
// invalid when I include this. */
.build();
String headerEnc = Base64Utility.encode(headerObj.toString().getBytes(), true);
// Create and Base64 encode the claims portion of the JWT
JsonObject claimsObj =
Json.createObjectBuilder()
.add("exp", (System.currentTimeMillis() / 1000) + 300) /* Expire time */
.add("iat", (System.currentTimeMillis() / 1000)) /* Issued time */
.add("aud", "acmeGifts") /* Audience */
.add("jti", Long.toHexString(System.nanoTime())) /* Unique value */
.add("sub", username) /* Subject */
.add("upn", username) /* Subject again */
.add("iss", JWT_ISSUER) /* Issuer */
.add("groups", getGroupArray(groups)) /* Group list */
.build();
String claimsEnc = Base64Utility.encode(claimsObj.toString().getBytes(), true);
String headerClaimsEnc = headerEnc + "." + claimsEnc;
// Open the keystore that the server will use to validate the JWT
KeyStore ks = KeyStore.getInstance("JCEKS");
InputStream ksStream = this.getClass().getResourceAsStream("/keystore.jceks");
char[] password = new String("secret").toCharArray();
ks.load(ksStream, password);
// Get the private key to use to sign the JWT. Normally we would not do this but
// we are pretending to be the user service here.
KeyStore.ProtectionParameter keyPassword = new KeyStore.PasswordProtection(password);
KeyStore.PrivateKeyEntry privateKeyEntry =
(KeyStore.PrivateKeyEntry) ks.getEntry("default", keyPassword);
PrivateKey privateKey = privateKeyEntry.getPrivateKey();
// Sign the JWT
Signature sig = Signature.getInstance(JWT_ALGORITHM);
sig.initSign(privateKey);
sig.update(headerClaimsEnc.getBytes());
String sigEnc = Base64Utility.encode(sig.sign(), true);
// Lets just check......
String jwtEnc = headerClaimsEnc + "." + sigEnc;
java.security.cert.Certificate cert = ks.getCertificate("default");
PublicKey publicKey = cert.getPublicKey();
validateJWT("Bearer " + jwtEnc, publicKey);
// Return the complete JWT (header, claims, signature).
return jwtEnc;
}
示例4: transformEncryptedKey
import java.security.GeneralSecurityException; //导入依赖的package包/类
public EncryptedKeyVersion transformEncryptedKey(EncryptedKeyVersion encryptedKeyVersion, ReEncryptionKeyInstance reKey)
throws IOException, GeneralSecurityException
{
CryptoCodec reCC = CryptoCodec.getInstance(conf, suite);
Encryptor encryptor = reCC.createEncryptor();
encryptor.init(reKey.getMaterial(), null);
int keyLen = encryptedKeyVersion.getEncryptedKeyVersion().getMaterial().length;
ByteBuffer bbIn = ByteBuffer.allocateDirect(keyLen);
ByteBuffer bbOut = ByteBuffer.allocateDirect(keyLen);
bbIn.put(encryptedKeyVersion.getEncryptedKeyVersion().getMaterial());
bbIn.flip();
encryptor.encrypt(bbIn, bbOut);
byte[] encryptedKey = new byte[bbOut.limit()];
bbOut.get(encryptedKey);
final String dstKeyNameVersion = reKey.getDstNameVersion();
return EncryptedKeyVersion.createForDecryption(KeyPairProvider.getBaseName(dstKeyNameVersion),
dstKeyNameVersion,
encryptedKeyVersion.getEncryptedKeyIv(), encryptedKey);
}
示例5: createRFC3211Wrapper
import java.security.GeneralSecurityException; //导入依赖的package包/类
Cipher createRFC3211Wrapper(ASN1ObjectIdentifier algorithm)
throws CMSException
{
String cipherName = (String)BASE_CIPHER_NAMES.get(algorithm);
if (cipherName == null)
{
throw new CMSException("no name for " + algorithm);
}
cipherName += "RFC3211Wrap";
try
{
return helper.createCipher(cipherName);
}
catch (GeneralSecurityException e)
{
throw new CMSException("cannot create cipher: " + e.getMessage(), e);
}
}
示例6: stringToKey
import java.security.GeneralSecurityException; //导入依赖的package包/类
private byte[] stringToKey(char[] secret, byte[] salt, byte[] params)
throws GeneralSecurityException {
int iter_count = DEFAULT_ITERATION_COUNT;
if (params != null) {
if (params.length != 4) {
throw new RuntimeException("Invalid parameter to stringToKey");
}
iter_count = readBigEndian(params, 0, 4);
}
byte[] tmpKey = randomToKey(PBKDF2(secret, salt, iter_count,
getKeySeedLength()));
byte[] result = dk(tmpKey, KERBEROS_CONSTANT);
return result;
}
示例7: createBlogComment
import java.security.GeneralSecurityException; //导入依赖的package包/类
@Override
public Message createBlogComment(GroupId groupId, LocalAuthor author,
@Nullable String comment, MessageId parentOriginalId,
MessageId parentCurrentId)
throws FormatException, GeneralSecurityException {
if (comment != null) {
int commentLength = StringUtils.toUtf8(comment).length;
if (commentLength == 0) throw new IllegalArgumentException();
if (commentLength > MAX_BLOG_COMMENT_LENGTH)
throw new IllegalArgumentException();
}
long timestamp = clock.currentTimeMillis();
// Generate the signature
BdfList signed = BdfList.of(groupId, timestamp, comment,
parentOriginalId, parentCurrentId);
byte[] sig = clientHelper
.sign(SIGNING_LABEL_COMMENT, signed, author.getPrivateKey());
// Serialise the signed message
BdfList message = BdfList.of(COMMENT.getInt(), comment,
parentOriginalId, parentCurrentId, sig);
return clientHelper.createMessage(groupId, timestamp, message);
}
示例8: encrypt
import java.security.GeneralSecurityException; //导入依赖的package包/类
/**
* Encrypts a given byte array based on a shared secret.
*
* @param bytes
* @return the encrypted bytes as Base64
* @throws GeneralSecurityException
* on any problem during encryption
*/
public static byte[] encrypt(byte[] bytes) throws GeneralSecurityException {
SecretKeySpec skeySpec = new SecretKeySpec(
Base64.decodeBase64(ENCRYPTION_KEY), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(bytes);
return Base64.encodeBase64(encrypted);
}
示例9: createResult
import java.security.GeneralSecurityException; //导入依赖的package包/类
/**
* Build the handler result.
*
* @param credentials the provided credentials
* @param profile the retrieved user profile
* @return the built handler result
* @throws GeneralSecurityException On authentication failure.
* @throws PreventedException On the indeterminate case when authentication is prevented.
*/
protected HandlerResult createResult(final ClientCredential credentials, final UserProfile profile)
throws GeneralSecurityException, PreventedException {
if (profile != null) {
final String id;
if (isTypedIdUsed) {
id = profile.getTypedId();
} else {
id = profile.getId();
}
if (StringUtils.isNotBlank(id)) {
credentials.setUserProfile(profile);
credentials.setTypedIdUsed(isTypedIdUsed);
return new DefaultHandlerResult(
this,
new BasicCredentialMetaData(credentials),
this.principalFactory.createPrincipal(id, profile.getAttributes()));
}
throw new FailedLoginException("No identifier found for this user profile: " + profile);
}
throw new FailedLoginException("Authentication did not produce a user profile for: " + credentials);
}
示例10: close
import java.security.GeneralSecurityException; //导入依赖的package包/类
@Override
public void close() throws IOException
{
try
{
// Write the last block
writeBlock(this.outputCipher.doFinal());
}
catch (final GeneralSecurityException e)
{
throw new RuntimeException(e);
}
// Write the MAC code
writeBlock(this.mac.doFinal());
this.wrapped.close();
this.dataStr.close();
}
示例11: getAesKey
import java.security.GeneralSecurityException; //导入依赖的package包/类
private SecretKey getAesKey(Path path, KeyPair pair)
{
if(Files.notExists(path))
return createAesKey(path, pair);
try
{
return loadAesKey(path, pair);
}catch(GeneralSecurityException | IOException e)
{
System.err.println("Couldn't load AES key!");
e.printStackTrace();
return createAesKey(path, pair);
}
}
示例12: commitAndDeployTest
import java.security.GeneralSecurityException; //导入依赖的package包/类
@Test(priority=10)
public void commitAndDeployTest() throws GeneralSecurityException{
DelegateExecution delegateExecution = mock(DelegateExecution.class);
CmsRelease cmsRelease = mock(CmsRelease.class);
when(cmsRelease.getReleaseId()).thenReturn(TEST_CI_ID / 2);
CmsCISimple cmsCISimpleEnv = mock(CmsCISimple.class);
when(cmsCISimpleEnv.getCiId()).thenReturn(TEST_CI_ID);
when(delegateExecution.getVariable("release")).thenReturn(cmsRelease);
when(delegateExecution.getVariable("env")).thenReturn(cmsCISimpleEnv);
cc.setRestTemplate(mockHttpClientPostCommitAndDeploy);
try {
cc.commitAndDeployRelease(delegateExecution);
} catch (GeneralSecurityException e) {
throw e;
}
}
示例13: a
import java.security.GeneralSecurityException; //导入依赖的package包/类
private void a(boolean z, String str, String str2, Map<String, Object> map, cw cwVar,
OnFailureCallBack onFailureCallBack) {
try {
RequestBody create;
Builder c = c(str);
if (z) {
create = RequestBody.create(a, a((Map) map));
} else {
create = RequestBody.create(a, c.a((Map) map).toString());
c.removeHeader("Authorization");
}
c.url(str2).post(create);
a(c.build(), cwVar, onFailureCallBack);
} catch (GeneralSecurityException e) {
if (onFailureCallBack != null) {
this.d.post(new bv(this, onFailureCallBack));
}
}
}
示例14: validate
import java.security.GeneralSecurityException; //导入依赖的package包/类
private void validate(final X509Certificate cert) throws GeneralSecurityException {
cert.checkValidity();
this.revocationChecker.check(cert);
int pathLength = cert.getBasicConstraints();
if (pathLength < 0) {
if (!isCertificateAllowed(cert)) {
throw new FailedLoginException(
"Certificate subject does not match pattern " + this.regExSubjectDnPattern.pattern());
}
if (this.checkKeyUsage && !isValidKeyUsage(cert)) {
throw new FailedLoginException(
"Certificate keyUsage constraint forbids SSL client authentication.");
}
} else {
// Check pathLength for CA cert
if (pathLength == Integer.MAX_VALUE && this.maxPathLengthAllowUnspecified != true) {
throw new FailedLoginException("Unlimited certificate path length not allowed by configuration.");
} else if (pathLength > this.maxPathLength && pathLength < Integer.MAX_VALUE) {
throw new FailedLoginException(String.format(
"Certificate path length %s exceeds maximum value %s.", pathLength, this.maxPathLength));
}
}
}
示例15: checkCertificate
import java.security.GeneralSecurityException; //导入依赖的package包/类
/**
* Test method for {@link AbstractCRLRevocationChecker#check(X509Certificate)}.
*/
@Test
public void checkCertificate() {
try {
for (final X509Certificate cert : this.certificates) {
getChecker().check(cert);
}
if (this.expected != null) {
Assert.fail("Expected exception of type " + this.expected.getClass());
}
} catch (final GeneralSecurityException e) {
if (this.expected == null) {
Assert.fail("Revocation check failed unexpectedly with exception: " + e);
} else {
final Class<?> expectedClass = this.expected.getClass();
final Class<?> actualClass = e.getClass();
Assert.assertTrue(
String.format("Expected exception of type %s but got %s", expectedClass, actualClass),
expectedClass.isAssignableFrom(actualClass));
}
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:25,代码来源:AbstractCRLRevocationCheckerTests.java