/** * 加密 由于RSA一次只能加密128个字节,所以将原始数据按100个字节分割,分块加密,最后将加密后的字节流连接起来。 (non-Javadoc) * * @see com.alipay.api.security.Encrypt#encrypt(java.lang.String, java.lang.String, * java.lang.String, com.alipay.api.enums.EncryptStyleEnum) */ public String encrypt(String content, String key) throws Exception { PublicKey pubkey = KeyReader.getPublicKeyFromX509(ALGORITHM, new ByteArrayInputStream(key.getBytes())); Cipher cipher = Cipher.getInstance(CIPHER_NAME); cipher.init(Cipher.ENCRYPT_MODE, pubkey); InputStream inputReader = new ByteArrayInputStream(content.getBytes("utf-8")); ByteArrayOutputStream writer = new ByteArrayOutputStream(); byte[] buf = new byte[100]; int bufl; while ((bufl = inputReader.read(buf)) != -1) { byte[] block = null; if (buf.length == bufl) { block = buf; } else { block = new byte[bufl]; for (int i = 0; i < bufl; i++) { block[i] = buf[i]; } } writer.write(cipher.doFinal(block)); } return new String(Base64.encodeBase64(writer.toByteArray())); }
void setDistributor(EventDistributor d) { touchScreen.addDistributorLinks(d); cardReader.addDistributorLinks(d); keyReader.addDistributorLinks(d); for (DPoint dp : dockingPoints) { dp.setDistributor(d); } }
/** * Implementation of docking station functionality for "view activity" use case. * * <p>Method called on docking station receiving a "view activity" triggering input event at the * touch screen. */ @Override public void viewActivityReceived() { logger.fine(getInstanceName()); touchScreen.showPrompt("PLEASE INSERT YOUR KEY."); String keyID = keyReader.waitForKeyInsertion(); ArrayList<String> userInfoData; userInfoData = hub.userActivity(keyID); touchScreen.showUserActivity(userInfoData); ; }
@Override public final DbxAppInfo read(JsonParser parser) throws IOException, JsonReadException { JsonLocation top = JsonReader.expectObjectStart(parser); String key = null; String secret = null; DbxHost host = null; while (parser.getCurrentToken() == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); parser.nextToken(); try { if (fieldName.equals("key")) { key = KeyReader.readField(parser, fieldName, key); } else if (fieldName.equals("secret")) { secret = SecretReader.readField(parser, fieldName, secret); } else if (fieldName.equals("host")) { host = DbxHost.Reader.readField(parser, fieldName, host); } else { // Unknown field. Skip over it. JsonReader.skipValue(parser); } } catch (JsonReadException ex) { throw ex.addFieldContext(fieldName); } } JsonReader.expectObjectEnd(parser); if (key == null) throw new JsonReadException("missing field \"key\"", top); if (secret == null) throw new JsonReadException("missing field \"secret\"", top); if (host == null) host = DbxHost.Default; return new DbxAppInfo(key, secret, host); }