本文整理汇总了Java中com.yahoo.athenz.auth.util.Crypto.loadPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java Crypto.loadPublicKey方法的具体用法?Java Crypto.loadPublicKey怎么用?Java Crypto.loadPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.yahoo.athenz.auth.util.Crypto
的用法示例。
在下文中一共展示了Crypto.loadPublicKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadPublicKeys
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
void loadPublicKeys(ArrayList<PublicKeyEntry> publicKeys, Map<String, PublicKey> keyMap) {
if (publicKeys == null) {
return;
}
for (PublicKeyEntry publicKey : publicKeys) {
String id = publicKey.getId();
String key = publicKey.getKey();
if (key == null || id == null) {
continue;
}
PublicKey pubKey = null;
try {
pubKey = Crypto.loadPublicKey(Crypto.ybase64DecodeString(key));
} catch (Exception e) {
LOG.error("Invalid ZTS public key for id: " + id + " - " + e.getMessage());
continue;
}
keyMap.put(id, pubKey);
}
}
示例2: validate
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
public boolean validate(String pubKey, int allowedOffset, boolean allowNoExpiry,
StringBuilder errMsg) {
errMsg = errMsg == null ? new StringBuilder(512) : errMsg;
if (pubKey == null) {
errMsg.append("Token:validate: token=").append(unsignedToken).
append(" : No public key provided");
LOG.error(errMsg.toString());
return false;
}
PublicKey publicKey = null;
try {
publicKey = Crypto.loadPublicKey(pubKey);
} catch (Exception e) {
errMsg.append("Token:validate: token=").append(unsignedToken).
append(" : unable to load public key due to Exception=").
append(e.getMessage());
LOG.error(errMsg.toString());
return false;
}
return validate(publicKey, allowedOffset, allowNoExpiry, errMsg);
}
示例3: testX509CSRrequest
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test(dataProvider = "x500Principal")
public void testX509CSRrequest(String x500Principal, boolean badRequest) throws Exception{
PublicKey publicKey = Crypto.loadPublicKey(rsaPublicKey);
PrivateKey privateKey = Crypto.loadPrivateKey(rsaPrivateKey);
String certRequest = null;
GeneralName otherName1 = new GeneralName(GeneralName.otherName, new DERIA5String("role1"));
GeneralName otherName2 = new GeneralName(GeneralName.otherName, new DERIA5String("role2"));
GeneralName[] sanArray = new GeneralName[]{otherName1, otherName2};
try {
certRequest = Crypto.generateX509CSR(privateKey, publicKey, x500Principal, sanArray);
} catch (Exception e){
if (!badRequest){
fail("Should not have failed to create csr");
}
}
if (!badRequest){
//Now validate the csr
Crypto.getPKCS10CertRequest(certRequest);
}
}
示例4: loadZMSPublicKeys
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
void loadZMSPublicKeys() {
final String rootDir = ZTSImpl.getRootDir();
String confFileName = System.getProperty(ZTSConsts.ZTS_PROP_ATHENZ_CONF,
rootDir + "/conf/athenz/athenz.conf");
Path path = Paths.get(confFileName);
AthenzConfig conf = null;
try {
conf = JSON.fromBytes(Files.readAllBytes(path), AthenzConfig.class);
ArrayList<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = conf.getZmsPublicKeys();
if (publicKeys != null) {
for (com.yahoo.athenz.zms.PublicKeyEntry publicKey : publicKeys) {
String id = publicKey.getId();
String key = publicKey.getKey();
if (key == null || id == null) {
continue;
}
PublicKey zmsKey = Crypto.loadPublicKey(Crypto.ybase64DecodeString(key));
zmsPublicKeyCache.put(id, zmsKey);
}
}
} catch (IOException e) {
LOGGER.info("Unable to parse conf file " + confFileName);
return;
}
}
示例5: verifyInstanceDocument
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
public boolean verifyInstanceDocument(OSTKInstanceInformation info, String publicKey) {
// for now we're only validating the document signature
boolean verified = false;
try {
final PublicKey pub = Crypto.loadPublicKey(publicKey);
verified = Crypto.verify(info.getDocument(), pub, info.getSignature());
if (!verified) {
LOGGER.error("verifyInstanceDocument: OSTK document signature did not match");
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("verifyInstanceDocument: OSTK document signature matched");
}
} catch (Exception ex) {
LOGGER.error("verifyInstanceDocument: Unable to verify signature: {}",
ex.getMessage());
}
return verified;
}
示例6: testSignVerifyRSAKey
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyRSAKey() {
PrivateKey privateKey = Crypto.loadPrivateKey(rsaPrivateKey);
assertNotNull(privateKey);
String signature = Crypto.sign(serviceToken, privateKey);
assertEquals(signature, serviceRSASignature);
PublicKey publicKey = Crypto.loadPublicKey(rsaPublicKey);
assertNotNull(publicKey);
assertTrue(Crypto.verify(serviceToken, publicKey, signature));
}
示例7: testSignVerifyRSAKey_Invalid
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyRSAKey_Invalid() {
PublicKey publicKey = Crypto.loadPublicKey(rsaPublicInvalidKey);
assertNotNull(publicKey);
assertFalse(Crypto.verify(serviceToken, publicKey, serviceRSASignature));
}
示例8: testSignVerifyRSAKey_X509
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyRSAKey_X509() {
PublicKey publicKey = Crypto.loadPublicKey(rsaPublicX590Cert);
assertNotNull(publicKey);
assertTrue(Crypto.verify(serviceToken, publicKey, serviceRSASignature));
}
示例9: testSignVerifyECKey_Invalid
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyECKey_Invalid() {
PublicKey publicKey = Crypto.loadPublicKey(ecPublicInvalidKey);
assertNotNull(publicKey);
assertFalse(Crypto.verify(serviceToken, publicKey, serviceECSignature));
}
示例10: testSignVerifyECKey_X509
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyECKey_X509() {
PublicKey publicKey = Crypto.loadPublicKey(ecPublicX509Cert);
assertNotNull(publicKey);
assertTrue(Crypto.verify(serviceToken, publicKey, serviceECSignature));
}
示例11: verifyServicePublicKey
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
boolean verifyServicePublicKey(String key) {
try {
PublicKey pub = Crypto.loadPublicKey(Crypto.ybase64DecodeString(key));
if (LOG.isDebugEnabled()) {
LOG.debug("verifyServicePublicKey: public key looks valid: " + pub);
}
} catch (Exception ex) {
LOG.error("verifyServicePublicKey: Invalid Public Key: " + ex.getMessage());
return false;
}
return true;
}
示例12: fromYbase64EncodedKey
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
private static AthenzPublicKey fromYbase64EncodedKey(String encodedKey, String keyId) {
return new AthenzPublicKey(Crypto.loadPublicKey(Crypto.ybase64DecodeString(encodedKey)), keyId);
}
示例13: validateForAuthorizedService
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
public boolean validateForAuthorizedService(String pubKey, StringBuilder errMsg) {
errMsg = errMsg == null ? new StringBuilder(512) : errMsg;
if (authorizedServiceSignature == null) {
errMsg.append("PrincipalToken:validateForAuthorizedService: token=").
append(unsignedToken).
append(" : missing data/signature component: public key=").
append(pubKey);
LOG.error(errMsg.toString());
return false;
}
int idx = signedToken.indexOf(";bs=");
if (idx == -1) {
errMsg.append("PrincipalToken:validateForAuthorizedService: token=").
append(unsignedToken).append(" : not signed by any authorized service");
LOG.error(errMsg.toString());
return false;
}
String unsignedAuthorizedServiceToken = signedToken.substring(0, idx);
if (pubKey == null) {
errMsg.append("PrincipalToken:validateForAuthorizedService: token=").
append(unsignedToken).append(" : No public key provided");
LOG.error(errMsg.toString());
return false;
}
PublicKey pub = null;
boolean verified = false; // fail safe
try {
pub = Crypto.loadPublicKey(pubKey);
verified = Crypto.verify(unsignedAuthorizedServiceToken, pub, authorizedServiceSignature);
if (verified == false) {
errMsg.append("PrincipalToken:validateForAuthorizedService: token=").
append(unsignedToken).append(" : authentication failed: public key=").
append(pubKey);
LOG.error(errMsg.toString());
} else if (LOG.isDebugEnabled()) {
LOG.debug("validateForAuthorizedService: Token: " + unsignedToken +
" - successfully authenticated");
}
} catch (Exception e) {
errMsg.append("PrincipalToken:validateForAuthorizedService: token=").
append(unsignedToken).
append(" : authentication failed verifying signature: exc=").
append(e.getMessage()).append(" : public key=").append(pubKey);
LOG.error(errMsg.toString());
}
return verified;
}
示例14: testSignVerifyECKey
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyECKey() {
PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateKey);
assertNotNull(privateKey);
String signature = Crypto.sign(serviceToken, privateKey);
PublicKey publicKey = Crypto.loadPublicKey(ecPublicKey);
assertNotNull(publicKey);
assertTrue(Crypto.verify(serviceToken, publicKey, signature));
}
示例15: testSignVerifyECParamPrime256v1Key
import com.yahoo.athenz.auth.util.Crypto; //导入方法依赖的package包/类
@Test
public void testSignVerifyECParamPrime256v1Key() {
PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateParamPrime256v1Key);
assertNotNull(privateKey);
String signature = Crypto.sign(serviceToken, privateKey);
PublicKey publicKey = Crypto.loadPublicKey(ecPublicParamPrime256v1Key);
assertNotNull(publicKey);
assertTrue(Crypto.verify(serviceToken, publicKey, signature));
}